我在Selenium WebDriver中使用
Java编写了几个测试用例,并在网格(集线器和多个节点)上执行它们.我注意到,由于NoSuchElementException,几个测试用例失败.什么是避免NoSuchElementException和确保元素总是找到最好和最强大的方法?
解决方法
你永远不能确定该元素将被发现,实际上这是功能测试的目的 – 告诉你页面上是否有任何改变.但有一点肯定有帮助的是添加等待通常导致NoSuchElementException的元素
WebDriverWait wait = new WebDriverWait(webDriver,timeoutInSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));