【问题标题】:click doesn't work with InternetExplorerDriver Selenium单击不适用于 InternetExplorerDriver Selenium
【发布时间】:2012-10-23 07:27:19
【问题描述】:

我正在为 ASP .NET Webforms 应用程序开发大量测试。为此,我将 Selenium 与 InternetExplorerDriver 一起使用。

但是,我有一个我无法解决的问题。有时,当我调用元素的“单击”方法时,单击不起作用。在 Internet Explorer 中,按钮看起来像是被点击了,但在应用程序中没有触发 click 事件。你有想法吗 ?

最后一个问题:你如何知道 Selenium 的回发何时结束? WebForms 和 UpdatePanel 使用 Postbacks 来刷新内容。所以,我无法验证一个特定元素的存在......

感谢您的回答!

PS:我正在使用 IE 9 / IE 10 和 Selenium For .NET 2.25.1

【问题讨论】:

  • 问题是否仅特定于 IE 驱动程序?
  • 是的。用 FirefoxDriver 没问题

标签: selenium webforms postback


【解决方案1】:

我通过以下方式解决了这个问题:

 driver.findElement(By locator).sendKeys("\n");

要与可能已更改的元素进行交互,请尝试 fluentWait:

 public WebElement fluentWait(final By locator){
            Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                    .withTimeout(30, TimeUnit.SECONDS)
                    .pollingEvery(5, TimeUnit.SECONDS)
                    .ignoring(org.openqa.selenium.NoSuchElementException.class);
            WebElement foo = wait.until(
                    new Function<WebDriver, WebElement>() {
                        public WebElement apply(WebDriver driver) {
                            return driver.findElement(locator);
                        }
                    }
            );
            return  foo;              }     ;

关于fluentWait的详情可以获取here

所以假设你有元素应该被改变,例如跟随 xPath:

String xPathElement ="blablabla";

fluentWait(By.xpath(xPathElement)).sendKeys("\n");

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 2011-12-30
    相关资源
    最近更新 更多