java Selenium junit测试失败,驱动程序过早获取URL
我正在努力通过这次考试。 我正在检查网页URL是否等于预期的URL
但是,驱动程序在加载下一页之前一直获取URL,因此它会不断检查旧URL与预期URL
driver.findElement(By.id("keywords")).sendKeys("Arlo Lamp");
driver.findElement(By.className("search-form")).submit();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='onetrust-accept-btn-handler']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//ol[@class='product-list product-list-main']/li//a"))).click();
String url = driver.getCurrentUrl();
System.out.println(url);
assertEquals("https://www.dunnesstores.com/p/arlo-lamp/7761102?colour=Cream", url);
这应该是它所断言的页面
取而代之的是,它会在点击它一直断言的项目之前关闭页面
# 1 楼答案
您可以像这样等待该URL:
或者等待某个特定于该页面的UI元素