![](/img/trans.png)
[英]Selenium clicks an element 'successfully', yet, it is not actually clicked
[英]Selenium says element clicked 'successfully', but, it is not actually clicked
我有一个场景,我需要点击继续按钮。即使我在点击功能后给出了打印消息。消息正在打印,但按钮没有点击。我试过 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");
}
在浏览器中打开所需页面并打开浏览器控制台。 在同一个 $("input[id='btnWFContinue']").click() 或 document.getElementById("btnWFContinue").click() 中执行以下代码
如果元素是可点击的,那么上面的 javascript 命令必须更改网页。 在您的脚本中也使用相同的内容。 其他没有与您的元素关联的点击事件。
尝试在 if 语句之前放置一个等待语句。 有可能代码在加载元素之前执行并且代码跳转到 else 部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.