【问题标题】:PhantomJS is clearing out fields after sendKeys had previously populated them在 sendKeys 之前填充字段后,PhantomJS 正在清除字段
【发布时间】: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


    【解决方案1】:

    使用 Enter 修复问题:

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

    【讨论】:

    • 谢谢,机器人!非常感谢!
    猜你喜欢
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多