Single click in selenium acts as double click
L

1

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.

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();
Lightman answered 26/7, 2017 at 5:53 Comment(13)
The problem could be the expression you put inside your XPath if you have some element which match, try to restrict your XPath expression to be sure it's unique.Demonic
Try setting NATIVE_EVENTS to true and let us know the status. ThanksEnzootic
If I set "NATIVE_EVENTS" false, sendkeys work too slow.Lightman
@InferOn: xpath added is unique. Same window opens twice.Lightman
what is the IE version?Caparison
@NehaBagtharia Thats what I mentioned, instead of "NATIVE_EVENTS" false try setting NATIVE_EVENTS to true. ThanksEnzootic
@DebanjanB: I rectify myself sendkeys works slow if I set "NATIVE_EVENTS" to true.Lightman
@NehaBagtharia Fixup the slow sendKeys through 32 bit exe. ThanksEnzootic
@NehaBagtharia Incase its a public URL can you share the URL along with the manual steps? Ensure that you are using Selenium 3.4 along with IEDriverServer 3.4.0. Please do mention IE version as well. ThanksEnzootic
@DebanjanB: Thank you. I was using older version of selenium. Updating it resolved my issue.Lightman
@DebanjanB: Sure. Thanks!Lightman
@NehaBagtharia Check out my Answer. ThanksEnzootic
@Grasshopper: IE11Lightman
E
1

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: 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: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.

You can find more documentation about these facts in this link.

Sample Code Block:

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);
Enzootic answered 26/7, 2017 at 7:40 Comment(3)
This answer resolved the issue while working with basic java code. Maven projects works well with selenium 3.0.1 and not with any updated version. And in old version of selenium, the click issue exists.Lightman
Great news :) I do follow the maven queue haven't observed any question on IE-Maven combo? Did you raise one? Can you share the link please? ThanksEnzootic
No. I haven't yet raised the issue.Lightman

© 2022 - 2024 — McMap. All rights reserved.