硒中的单击代表双击 [英] Single click in selenium acts as double click

查看:91
本文介绍了硒中的单击代表双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的代码,单击链接即可打开一个新窗口.但是在执行脚本时,单击相当于双击同一元素,并打开2个窗口.

I have a simple code where I click on a link and it opens up a new window. But while executing the script, single click acts as double click on the same element and 2 windows are opened.

我正在使用InternetExplorer驱动程序

I am using InternetExplorer driver

String baseURL = "URL_to_opened";

DesiredCapabilities cap = DesiredCapabilities.internetExplorer();

cap.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);

cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

 WebDriver driver = new InternetExplorerDriver(cap);

driver.get(baseURL);

driver.findElement(By.xpath("Element to be clicked")).click();

推荐答案

使用 Selenium 3.4.0 时,将 IEDriverServer 3.4.0 IE(v 10/11) ,您可以考虑通过 DesiredCapabilities 类传递以下配置属性:

When you work with Selenium 3.4.0, IEDriverServer 3.4.0 with IE(v 10/11), you may consider passing the following configuration properties through DesiredCapabilities Class:

Native Events :由于InternetExplorerDriver仅用于Windows,因此它尝试使用所谓的本地"事件或OS级事件在浏览器中执行鼠标和键盘操作.这与对相同的操作使用模拟的JavaScript事件形成对比.使用本机事件的优点是它不依赖JavaScript沙箱,并且可以确保JavaScript事件在浏览器中正确传播.但是,当IE浏览器窗口没有焦点并且试图将鼠标悬停在元素上时,鼠标事件当前存在一些问题.

Native Events: As the InternetExplorerDriver is Windows-only, it attempts to use so-called "native", or OS-level events to perform mouse and keyboard operations in the browser. This is in contrast to using simulated JavaScript events for the same operations. The advantage of using native events is that it does not rely on the JavaScript sandbox, and it ensures proper JavaScript event propagation within the browser. However, there are currently some issues with mouse events when the IE browser window does not have focus, and when attempting to hover over elements.

Browser Focus :挑战在于IE本身似乎不完全尊重我们发送IE浏览器窗口(WM_MOUSEDOWN和WM_MOUSEUP)的Windows消息(如果窗口没有焦点).具体而言,被单击的元素将在其周围收到一个焦点窗口,但单击不会被该元素处理.可以说,我们根本不应该发送消息.相反,我们应该使用SendInput()API,但是该API明确要求窗口具有焦点.

Browser Focus:The challenge is that IE itself appears to not fully respect the Windows messages we send the IE browser window (WM_MOUSEDOWN and WM_MOUSEUP) if the window doesn't have the focus. Specifically, the element being clicked on will receive a focus window around it, but the click will not be processed by the element. Arguably, we shouldn't be sending messages at all; rather, we should be using the SendInput() API, but that API explicitly requires the window to have the focus.

您可以在 链接 .

示例代码块:

DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true);
cap.setCapability(InternetExplorerDriver.REQUIREWINDOWFOCUS, true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(cap);

这篇关于硒中的单击代表双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆