簡體   English   中英

Selenium Web Driver似乎間歇性地跳過driver.get()

[英]Selenium Web Driver seems to skip driver.get() intermittently

我有一個用Java編寫的針對Liferay網站的Selenium Web Driver測試。

// Login
driver.get(baseUrl + "/");
driver.findElement(By.id("_58_login")).sendKeys(login);
driver.findElement(By.id("_58_password")).sendKeys(password);
driver.findElement(By.xpath("//input[@value='Sign In']")).click();

// Try to navigate to dashboard and expect error
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Liferay")));
driver.get(baseUrl + "/user/tm2/so/dashboard");
driver.findElement(By.xpath("//h3[contains(., 'Not Found')]"));

問題是,間歇地(大約50%的時間),測試失敗,並出現異常org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//h3[contains(., 'Not Found')]"}

在測試過程中觀察Web驅動程序的瀏覽器行為時,發生的是登錄例程按預期方式工作,單擊“登錄”按鈕。 但是,一旦頁面到達登錄頁面,它將掛起30秒(我的隱式超時設置),並引發異常。

我的懷疑是driver.get(baseUrl + "/user/tm2/so/dashboard")調用以某種方式被跳過了。 您可以看到我已經設置了一個WebDriverWait來嘗試阻止driver.get導航在登錄例程完成之前進行,但似乎無濟於事。

有任何想法嗎?

更新:我發現問題與Selenium不相關-這是應用程序本身的問題,有時導航到URL只會刷新當前頁面。

沒問題,將代碼改為如下所示:

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
           .withTimeout(30, SECONDS)
           .pollingEvery(5, SECONDS)
           .ignoring(NoSuchElementException.class, ElementNotFoundException.class);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Liferay")));
driver.get(baseUrl + "/user/tm2/so/dashboard");
driver.findElement(By.xpath("//h3[contains(., 'Not Found')]"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM