PhantomJS在sendKeys之前填充后清除字段

时间:2014-09-13 05:21:20

标签: c# selenium-webdriver phantomjs bots

我等待元素出现然后我尝试用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);

我尝试填充的元素是在组合框选择时出现的文本框。我点击组合框中的元素 - >显示文本框(在组合框中选择项目之前隐藏它)。

1 个答案:

答案 0 :(得分:-1)

使用Enter修复了已发布的:

zipcode.SendKeys(text);
zipcode.SendKeys(OpenQA.Selenium.Keys.Enter);