我正在使用Selenium Webdriver(Java)进行编码测试,获得https://cloud.google.com作为驱动程序。我首先查找搜索输入字段sendKeys(“搜索短语\ n”)。在该页面开始更改其内容之后,我尝试使用WebDriverWait进行这些更改:
// first Wait - is to wait before page starts changing is content by removing search google icon
new WebDriverWait(driver, 30).until(ExpectedConditions.invisibilityOf(searchInputFieldIcon));
//second Wait - i'm waiting new hyperlink to appear (this hyperlink appears in search results after the whole page is asynchronically reloaded without page reloading)
new WebDriverWait(driver,30)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@href='https://cloud.google.com/products/calculator']")));
关键是,等待不会在元素显示之前等待30秒。代码只会引发异常:
org.openqa.selenium.NoSuchElementException:
no such element: Unable to locate element: {"method":"xpath","selector":"//a[@href='https:`//cloud.google.com/products/calculator']"}`
任何帮助将不胜感激!
请检查所附的屏幕截图。这里的Href链接不同于您在代码中使用的链接。
您可以使用下面的代码
wait.until(expectedConditions.visibilityOfElementLocated(By.linkText("Google Cloud Platform Pricing ")));