0
這種加載導航鏈接頁面的方法,需要時間來測試提交。我的測試在檢查頁面加載了正確的URL時下降。我試着寫:如何在Selenium 2的方法中寫入等待?
waitForElementToBeDisplayed(driver.findElement(By.xpath("//a[contains(.,'"+submenus[i]+"')]")), 500);
Thread.sleep(2000);
這是我的代碼:
public void showNavigationLinks(){
Actions action = new Actions(driver);
String[] submenus = {"Accessories", "iMacs", "iPads" , "iPhones" , "iPods" , "MacBook"};
for(int i=0;i<submenus.length;i++)
{
waitForElementToBeDisplayed(driver.findElement(By.xpath("//a[contains(.,'Product Category')]")), 500);
WebElement we = driver.findElement(By.xpath("//a[contains(.,'Product Category')]"));
action.moveToElement(we).moveToElement(driver.findElement(By.xpath("//a[contains(.,'"+submenus[i]+"')]"))).click().build().perform();
//Checking correct URL
waitForElementToBeDisplayed(driver.findElement(By.xpath("//a[contains(.,'"+submenus[i]+"')]")), 500);
Assert.assertTrue("checking if URL contains: " + submenus[i],
driver.getCurrentUrl().toLowerCase().contains(submenus[i].toLowerCase()));
}
}
這是我的錯誤:
java.lang.AssertionError: checking if URL contains: iMacs
當我把你的代碼放到這個錯誤:org.openqa.selenium.TimeoutException:預期的條件失敗:等待url包含「附件」。當前網址:「http://store.demoqa.com/products-page/product-category/accessories/」(用500次MILLISECONDS間隔試用60秒) –
@DyJon在這種情況下,您應該使用'toLower' 。我相應地更新了我的答案。 –
現在這是錯誤:org.openqa.selenium.TimeoutException:預期的情況失敗:等待url包含「ipods」。當前網址:「http://store.demoqa.com/products-page/product-category/iphones/」(以500次MILLISECONDS間隔嘗試60秒) –