硒和含C#的幻影。等待问题
我一直在自学如何使用Selenium和Phantom JS,但我遇到了一个难题 尽管进行了多次尝试,我仍然无法实现等待 以下是我的主要尝试: 驾驶员信息:硒和含C#的幻影。等待问题,c#,selenium,phantomjs,C#,Selenium,Phantomjs,我一直在自学如何使用Selenium和Phantom JS,但我遇到了一个难题 尽管进行了多次尝试,我仍然无法实现等待 以下是我的主要尝试: 驾驶员信息: _wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 5)); 网址: 方法: public static string GetValueFromKeyAndCountry(string key, string country, string category) { string
_wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 5));
网址:
方法:
public static string GetValueFromKeyAndCountry(string key, string country, string category)
{
string res = string.Empty;
IWebElement dropDownCountryList = _driver.FindElement(By.XPath("//select[@name='selecter_links']"));
SelectElement countryList = new SelectElement(dropDownCountryList);
countryList.SelectByText(country);
IWebElement pE = _driver.FindElement(By.XPath("//h2[@sectiontitle='" + category + "']"));
pE.Click();
IWebElement mainElement = pE.FindElement(By.XPath("//span[contains(.,'" + key + "')]"));
Console.WriteLine("-----LOG: \n-Tagname: " + mainElement.TagName + " \n-Attribute: " + mainElement.GetAttribute("class") + " \n-Text: " + mainElement.Text);
IWebElement parent = GetParent(mainElement);
Console.WriteLine("-----LOG: \n-Tagname: " + parent.TagName + " \n-Attribute: " + parent.GetAttribute("class") + " \n-Text: " + parent.Text);
//------ This is the main part. I wait for the element to be found and I return its contents.
_wait.Until((d) =>
{
return parent.FindElement(By.XPath(".//span[@class='category_data']"));
});
mainElement = parent.FindElement(By.XPath(".//span[@class='category_data']"));
return mainElement.Text;
}
方法调用:
string president =
PropertyManager.GetValueFromKeyAndCountry("head of government: ", "Colombia", "Government");
网页结构:
我不想使用隐式等待。我希望等待元素可用,但此代码似乎不正确。我不知道我错过了什么
任何指示都将受到极大的赞赏,甚至是一种替代解决方案(当然这不是隐含的等待)
string president =
PropertyManager.GetValueFromKeyAndCountry("head of government: ", "Colombia", "Government");