我遇到了一个无法解决的 Selenium 问题。 我收到以下错误”
no such element: Unable to locate element:{"method":"id","selector":"menu-supply-approval-queue"}
我知道问题在于等待。 所以我做了下一个方法:
public static WebElement getWebElementByIdWithWait(String id)
{
WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));
return WebDriverMgr.waitForElementToBeClickable(By.id(id));
}
但是 selenium 不会等待,并再次出现此错误:
Thu Sep 12 16:56:45 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"menu-supply-approval-queue"}
(Session info: chrome=76.0.3809.132)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
有人可以建议如何让 Selenium 等待元素显示/可点击吗? 它不再等待
更奇怪的是selenium实际上返回了元素然后点击它,所以如果他找不到它怎么返回它?它只会弄乱日志
这是有效的代码,但它使用 sleep
public static WebElement getWebElementByIdWithWait(String id)
{
Logger.sleep(60000);
// WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 8);
// wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));
return WebDriverMgr.waitForElementToBeClickable(By.id(id));
}
问候
最佳答案
此错误消息...
Thu Sep 12 16:56:45 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"menu-supply-approval-queue"}
(Session info: chrome=76.0.3809.132)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
...意味着 ChromeDriver 无法启动/生成新的 WebBrowser,即 Chrome 浏览器 session 。
您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:
- 您正在使用 chromedriver=2.36
- chromedriver=2.36 的发行说明明确提到以下内容:
Supports Chrome v63-65
- 您正在使用 chrome=76.0
- ChromeDriver v76.0 的发行说明明确提到以下内容:
Supports Chrome version 76
- 您的JDK版本是1.8.0_65,这是相当古老的。
因此,JDK v8u65、ChromeDriver v2.36 和 Chrome 浏览器 v76.0 之间存在明显不匹配
<小时/>解决方案
确保:
- JDK 已升级到当前级别 JDK 8u222 .
- ChromeDriver 已更新为当前 ChromeDriver v77.0级别。
- Chrome 已更新至当前 Chrome 版本 77.0 级别。 (根据 ChromeDriver v77.0 release notes )
- 以非root用户身份执行
@Test
。
关于java - 让 selenium 等待 - WebDriverWait 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57908501/