【发布时间】: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。
【问题讨论】:
-
不管浏览器如何,selenium 有时都无法点击找到的元素。一种选择是尝试通过 Javascript 使用
JavascriptExecutor。您也可以尝试,测试,在点击之前等待一段时间,因为这可能是由于执行中的竞争条件而发生的。
标签: .net selenium internet-explorer internet-explorer-11