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:期待された条件は失敗しました: "Accessories"を含むURLを待っています。現在のURL: "http://store.demoqa.com/products-page/product-category/accessories/"(500ミリ秒の間隔で60秒間試しました) –
@DyJonこの場合、あなたは 'toLower'を使うべきです。それに応じて私の答えを更新しました。 –
これは今エラーです:org.openqa.selenium.TimeoutException:期待された条件は失敗しました: "ipods"を含むURLを待っています。現在のURL: "http://store.demoqa.com/products-page/product-category/iphones/"(500ミリリットル間隔で60秒間試しました) –