问题描述:

I'm trying to click on a standard HTML button. The driver is locating the element correctly and the Click() method completes without exception but the click isn't being invoked on the browser.

The example below just opens the Google homepage and clicks (or fails to click) the I feel lucky button.

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"));

}

}

I'm using the 32-bit version of IEDriverServer.exe.

I'm using IE version 11.576.14393.0.

Update version: 11.0.38.

The other solutions have the same (non) affect, however, I have found a useful wait condition ElementToBeClickable.

网友答案:

Adding the ExpectedConditions.ElementToBeClickable wait condition solved the problem.

[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"));
    }
}
相关阅读:
Top