5

Selenium Webdriver (Java) を使用してサイトをテストしたいのですが、そのサイトには ajax が含まれており、HTMLUnit は ajax コンテンツを認識しません。

回避策はありますか?

例:

WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
//login into your account
this.login(driver);
//click on edit Profile Link into an ajax-loaded tab
driver.findElement(By.id("editProfile")).click();
//Result: org.openqa.selenium.NoSuchElementException 
4

1 に答える 1

5

要素との相互作用の前に待機条件を使用し、ajax 応答の後に表示する必要があります。

WebDriverWait wait = new WebDriverWait(webDriver, 5);
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_to_element")));

これにより、webDriver は要素を 5 秒間待機します。この質問は以前に尋ねられました。

于 2012-04-11T11:38:23.303 に答える