【发布时间】:2014-09-13 16:45:13
【问题描述】:
我等待一个元素出现然后我尝试用SendKeys 填充它。即使元素已启用并显示,40% 的时间也不会填充元素。我到处都是各种值的Thread.Sleep。
我的问题与one 类似,但我使用的是 PhantomJS 驱动程序而不是 Firefox 驱动程序。使用上面链接中的解决方案不起作用,我只是得到了未定义的函数异常。
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(by));
}
return driver.FindElement(by);
}
zipcode = _driver.FindElement(By.Name("iZipCode"), 50);
while(!zipcode.Displayed)
{
System.Threading.Thread.Sleep(3000);
}
zipcode.Click();
zipcode.Clear();
System.Threading.Thread.Sleep(3000);
zipcode.SendKeys(OpenQA.Selenium.Keys.Backspace);
zipcode.SendKeys(text);
我试图填充的元素是一个出现在组合框选择上的文本框。我单击组合框中的元素-> 显示文本框(在选择组合框中的项目之前隐藏)。
【问题讨论】:
标签: c# selenium-webdriver phantomjs bots