Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

348
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda