Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
How to highlight specific text using Selenium/ selenide and javacript executer

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>

This is how elements locate enter image description here

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);
                    
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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();

This worked for me (just found some similar site): enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!