【发布时间】:2019-09-12 14:05:28
【问题描述】:
我遇到了无法解决的硒问题。 我收到以下错误”
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 居然返回了元素,然后点击了它,所以如果他找不到它是如何返回的呢?它只是弄乱了日志
这是有效的代码,但它使用睡眠
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));
}
问候
【问题讨论】:
-
看起来您使用的是非常旧的 chromedriver。您可以将其升级到 76。
-
我认为它在 waitForElementToBeClickable 行上失败了?
-
显示有关错误的更多详细信息。也许是堆栈跟踪?
-
奇怪的是它没有失败,它只是把它放在日志中,
-
可以分享网址吗?
标签: java selenium google-chrome selenium-webdriver selenium-chromedriver