【问题标题】:Selenium .NET Click() not workingSelenium .NET Click() 不起作用
【发布时间】:2017-06-14 07:18:31
【问题描述】:

我正在尝试单击标准 HTML 按钮。驱动程序正确定位元素,Click() 方法无异常完成,但浏览器上未调用单击。

下面的例子只是打开谷歌主页并点击(或点击失败)我感到幸运按钮。

private static readonly InternetExplorerOptions INTERNET_EXPLORER_OPTIONS = new InternetExplorerOptions
{
    IgnoreZoomLevel = true
};

[Test]
public void Clicking()
{
    using (var driver = new InternetExplorerDriver(INTERNET_EXPLORER_OPTIONS))
    {
        driver.Navigate().GoToUrl("http://www.google.com");

        driver.FindElement(By.Name("btnI")).Click();

        Assert.That(driver.Url, Is.EqualTo("https://www.google.com/doodles"));
    }
}

我使用的是 32 位版本的 IEDriverServer.exe

我用的是IE版11.576.14393.0

更新版本:11.0.38

其他解决方案具有相同(非)影响,但是,我发现了一个有用的wait 条件ElementToBeClickable

【问题讨论】:

标签: .net selenium internet-explorer internet-explorer-11


【解决方案1】:

添加ExpectedConditions.ElementToBeClickable 等待条件解决了问题。

[Test]
public void Clicking()
{
    using (var driver = new InternetExplorerDriver())
    {
        driver.Navigate().GoToUrl("http://www.google.com");

        var button = driver.FindElement(By.Name("btnI"));
        Assert.That(button.TagName, Is.EqualTo("input"));

        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        wait.Until(ExpectedConditions.ElementToBeClickable(button));
        button.Click();
        wait.Until(webDriver => webDriver.Url == "https://www.google.com/doodles");  // <==  wait until condition here
        Assert.That(driver.Url, Is.EqualTo("https://www.google.com/doodles"));
    }
}

【讨论】:

    猜你喜欢
    • 2023-03-26
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2022-01-04
    相关资源
    最近更新 更多