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

115
Vistas
How to click on a Web Element using JS Executor and wait until script executed?

I have XPath of the button. I need to click on this button using JSExecutor and wait until script is executed. I suppose it can be done with ExpectedCondition.javaScriptThrowsNoExceptions(String script). But I don't know how implement it with XPath. I am using Java.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In my point of view, you must know what the button does

If there's a change in UI

ExpectedConditions.visibilityOf(WebElement element) will be better solution

In case javascript returns true/false, driver will wait the return from script execute

 new WebDriverWait(driver, Duration.ofSeconds(20)).until(new ExpectedCondition<Boolean>(){
    public Boolean apply(WebDriver driver) {
        JavascriptExecutor js = (JavascriptExecutor) driver;
        return (Boolean) js.executeScript("console.log('wait');return 1+1==2");
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Forming your xpath :

//tagname[@attributekey='attribute value']

after that pass it driver with wait

public By operation_first_Asset = By.xpath("//a[@analytics-category='Asset Operations']");

WebDriver driver = new ChromeDriver();


WebDriverWait wait = new WebDriverWait(driver, Duration.ofMinutes(2));


 /*
 * @param by, count, operation
 * wait based on the list of elements
 */
public void waitForElementToBe(By by, String action) {
    try {
        if (action.equals("click")) {
            wait.until(ExpectedConditions.elementToBeClickable(by));
        } else if (action.equals("visible")) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(by));
        } else if (action.equals("invisible")) {
            wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
        } else if (action.equals("presence")) {
            wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(by));
        }
    } catch (Exception err) {
        err.printStackTrace();
        throw err;
    }
}
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