I'm using selenium/ Selenide java test automation and I need to highlight the word 'Environment'. This need to be done using mouse event either double click on that or mouse move.
Once this is done I should able to see another window.
Currently, I tried multiple ways to do that and didn't succeed. Looking for help on that.
This is the sample element I'm trying
<h2>Local Environment Setup</h2>
These are the ways I tried
//Try 1 double click using selenide
$(content).doubleClick();
//Try 2 double click using js
((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].dblclick;",content);
//Try 3 using x and y (This returns error saying MoveTargetOutOfBoundsException)
String jsDoubleClick =
"var target = arguments[0]; " +
"var offsetX = arguments[1]; " +
"var offsetY = arguments[2]; " +
"var rect = target.getBoundingClientRect(); " +
"var cx = rect.left + (offsetX || (rect.width / 2)); " +
"var cy = rect.top + (offsetY || (rect.height / 2)); " +
" " +
"emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
"emit('mouseup', {clientX: cx, clientY: cy}); " +
"emit('mousedown', {clientX: cx, clientY: cy, buttons: 1}); " +
"emit('mouseup', {clientX: cx, clientY: cy}); " +
"emit('click', {clientX: cx, clientY: cy, detail: 2}); " +
" " +
"function emit(name, init) { " +
"target.dispatchEvent(new MouseEvent(name, init)); " +
"} ";
((JavascriptExecutor)getWebDriver()).executeScript(jsDoubleClick, content, content.getLocation().x, content.getLocation().y);
Move the mouse to the element by coordinates from its center and Doubleclick with Actions:
//locate the element somehow
WebElement h2 = driver.findElement(By.xpath("//h2"));
// try to move to the _Environment_ world center, you have to find the x value
// 0 - is element center (for Selenium 4 W3C)
int x = -100; // -100 worked for this site
new Actions(driver).moveToElement(h2, x, 0).doubleClick().build().perform();