[英]Click method behaves differently when using ChromeDriver with Chrome and IEDriverServer with Internet Explorer 11
I have created xpath on chrome as : 我在chrome上创建了xpath:
"//a[@href[contains(.,'moduleCode=MASTER')]]"This xpath is working fine for chromedriver. 这个xpath适用于chromedriver。 However, when the same Xpath is being executed for IEDriverServer it throws error as below: 但是,当为IEDriverServer执行相同的Xpath时,它会抛出错误,如下所示:
\norg.openqa.selenium.ElementNotVisibleException: Cannot click on element (WARNING: The server did not provide any stacktrace information) org.openqa.selenium.ElementNotVisibleException:无法单击元素(警告:服务器未提供任何堆栈跟踪信息)\nCommand duration or timeout: 0 milliseconds 命令持续时间或超时:0毫秒\nBuild info: version: '3.10.0', revision: '176b4a9', time: '2018-03-02T19:03:16.397Z' 构建信息:版本:'3.10.0',修订版:'176b4a9',时间:'2018-03-02T19:03:16.397Z'
But another xpath: 但另一个xpath:
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true); capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true); capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true);works for both the ChromeDriver and IEDriverServer. 适用于ChromeDriver和IEDriverServer。
Not able to figure out why is there such difference in both the xpaths and why one of the xpath is not supported for IEDriverServer. 无法弄清楚为什么在xpath中存在这样的差异以及为什么IEDriverServer不支持其中一个xpath。
Capabilities used are as follows: 使用的能力如下:
\ncapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);\n capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,TRUE);\n capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true); capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP,true);\n capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true); capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,true);\n capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true); capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS,true);
As mentioned in the Selenium Documentation , 如Selenium文档中所述 ,
At a high level, WebDriver uses a browser's native XPath capabilities wherever possible. 在较高的层面上,WebDriver尽可能使用浏览器的本机XPath功能。 On those browsers that don't have native XPath support, we have provided our own implementation. 在那些没有本机XPath支持的浏览器上,我们提供了自己的实现。 This can lead to some unexpected behaviour unless you are aware of the differences in the various XPath engines. 除非您了解各种XPath引擎中的差异,否则这可能会导致一些意外行为。
Taking a leaf out from @JimEvans's answer in this discussion : 在本次讨论中从@ JimEvans的答案中摘出一个词:
The driver implementations for Firefox and Chrome are developed and maintained by the vendors for those browsers ( Mozilla and Google ) and those drivers have access to internals of the browser in ways that the IEDriverServer does not (and likely never will) have. Firefox和Chrome的驱动程序实现由供应商为这些浏览器( Mozilla和Google )开发和维护,并且这些驱动程序可以通过IEDriverServer没有(也可能永远不会)的方式访问浏览器的内部。
So there are some difference in the way driver implementations ideantify and click on elements. 因此,驱动程序实现ideantify和单击元素的方式有所不同。
While using IEDriverServer and Internet Explorer 11 Ensure that the nativeEvents
capability is set to true . 使用IEDriverServer和Internet Explorer 11时确保将nativeEvents
功能设置为true 。
capabilities.setCapability("nativeEvents", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.