Question

Whenever I run a WebDriver test in IE (using InternetExplorerDriver), where elements of a web page need to be clicked, the InternetExplorerDriver takes over my mouse.

This does not happen when I run my tests in either Chrome or Firefox. Is there a way to prevent IE tests from taking control of the mouse pointer?

Example code that causes the mouse pointer to be 'stolen':

public void clickButtonNamed(String buttonName) {
    driver.findElement(By.xpath("//div[contains(text(),'" + buttonName + "')]")).click();
}

public void dragAndDropElement(WebElement source, WebElement target) throws InterruptedException {
    action.dragAndDrop(source,target).build().perform();
}

//IE Driver initialization
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,true);
WebDriver driver = new InternetExplorerDriver(caps);
Was it helpful?

Solution

Is there a reason you set this property InternetExplorerDriver.REQUIRE_WINDOW_FOCUS to true? This is why IEDriver asks IE to take control your pointer.

To fix it, simply remove it or set it to false. This was introduced in 2.28.0.3, here's the quote from CHANGELOG:

Introduced the "requireWindowFocus" capability into the IE driver. When used in conjunction with the "nativeEvents" capability, the driver will attempt to bring the current IE window to the foreground before executing a mouse or keyboard event.

Also, when the requireWindowFocus capability is set to true, advanced user interactions will now use the Windows SendInput() API to execute the interactions. To enable this behavior, set the value of the
requiresWindowFocus capability to "true" when creating an instance of the IE driver. The default for this new capability is "false". This functionality is currently considered extremely experimental; use at your own risk.

OTHER TIPS

Using this setting will avoid IE to take over the mouse control while performing actions -

InternetExplorerOptions ieOp = new InternetExplorerOptions(); ieOp.disableNativeEvents();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top