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

121
Views
¿Cómo hacer clic en un elemento web usando JS Executor y esperar hasta que se ejecute el script?

Tengo XPath del botón. Necesito hacer clic en este botón usando JSExecutor y esperar hasta que se ejecute el script. Supongo que se puede hacer con ExpectedCondition.javaScriptThrowsNoExceptions(String script). Pero no sé cómo implementarlo con XPath. Estoy usando Java.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

En mi punto de vista, debes saber lo que hace el botón.

Si hay un cambio en la interfaz de usuario

ExpectedConditions.visibilityOf (elemento WebElement) será una mejor solución

En caso de que javascript devuelva verdadero/falso, el controlador esperará el retorno de la ejecución del script

 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 Report

0

Formando tu xpath:

//nombre de etiqueta[@attributekey='valor de atributo']

después de eso pásalo conductor con espera

 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 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!