我有一个需要单击继续按钮的场景。即使我在单击功能后给出了打印消息。消息正在打印但按钮没有单击。我尝试了Java脚本执行程序,明确等待(elementtobeclickable),但仍然没有单击。另一种解决方案是。这是我到目前为止尝试过的
By click_continue= By.xpath("//input[@id='btnWFContinue']");
if(driver.findElement(click_continue)!=null) {
waitVar.until(ExpectedConditions.elementToBeClickable(driver.findElement(click_continue)));
WebElement ele = driver.findElement(click_continue);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
log.info("Clicked on Continue!!!");
/*
WebElement element = driver.findElement(click_continue);
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
driver.findElement(click_continue).click(); */
}else {
log.info("Continue button is not present moving to next step");
}
如果该元素是可点击的,则上述javascript命令必须更改网页。在脚本中也使用相同的内容。其他没有与您的元素相关联的点击事件。