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.
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"); } });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; } }