Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

352
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda