2011-05-30 119 views

回答

-2
+0

我猜waitForPageLoad是當您使用硒RC使用。 Webdriver的情況如何?我正在使用Firefox驅動程序.... 我做了一些嘗試和錯誤,似乎沒有必要寫任何東西,只要我們提交表單。 有人可以請評論 – SK176H 2011-05-30 15:07:01

+0

查看http://stackoverflow.com/questions/10720325/selenium-webdriver-wait-for-complex-page-with-javascript-to-load – reinierpost 2012-08-14 12:46:12

0

我認爲硒2,你並不需要一個表格後等待使用Firefox的webdriver提交。

 element.sendKeys("34344343"); 
    webDriver.findElement(By.id("searchSubmitButton")).click(); 

WebElement columnInPostedPage = webDriver.findElement(By.xpath("//div[@id='content']/table/tbody/tr[2]/td[3]")); // 

如果內容是由JavaScript加載頁面加載後,你可以做這樣的事情的內容

 query.submit(); 

    long end = System.currentTimeMillis() + 5000; 
    while (System.currentTimeMillis() < end) { 
     WebElement result = webDriver.findElement(By.id("content")); 
     if (result.isDisplayed()) { 
      break; 
     } 
     //Thread.sleep(1000); 
    }   

    WebElement columnInPostedPage = webDriver.findElement(By.xpath("//div[@id='content']/table/tbody/tr[2]/td[3]")); // 
+0

無論Selenium 2是否會在點擊後等待( )'取決於頁面的加載方式。 – reinierpost 2012-08-14 12:45:17

+0

我認爲一個例外會讓你跳出時間循環。我不認爲這會奏效。您需要使用帶有.ignoring方法的WebDriverWait。 – djangofan 2013-03-12 17:08:46

3

只需使用FluentWait類:

/** 
* An implementation of the {@link Wait} interface that may have its timeout 
* and polling interval configured on the fly. 
* 
* <p>Each FluentWait instance defines the maximum amount of time to wait for 
* a condition, as well as the frequency with which to check the condition. 
* Furthermore, the user may configure the wait to ignore specific types of 
* exceptions whilst waiting, such as 
* {@link org.openqa.selenium.NoSuchElementException NoSuchElementExceptions} 
* when searching for an element on the page. 
* 
* <p>Sample usage: 
* <code><pre> 
* // Waiting 30 seconds for an element to be present on the page, checking 
* // for its presence once every 5 seconds. 
* Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) 
*  .withTimeout(30, SECONDS) 
*  .pollingEvery(5, SECONDS) 
*  .ignoring(NoSuchElementException.class); 
* 
* WebElement foo = wait.until(new Function<WebDriver, WebElement>() { 
*  public WebElement apply(WebDriver driver) { 
*  return driver.findElement(By.id("foo")); 
*  } 
* }); 
* 

WebDriverWait

+0

這是一個新班級嗎?我有2.39(的C#綁定),它似乎沒有在那裏。這是從哪裏來的?也許我錯過了一個 – 2014-01-27 17:07:24

-1
for (int second = 0;; second++) { 
      if (second >= 60) fail("timeout"); 
      try { if (isElementPresent(By.linkText("element"))) break; } catch (Exception e) {} 
      Thread.sleep(1000); 
     } 
+1

-1:Webdriver有其隱式和顯式等待的方法:[here](http://seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits) – 2012-12-27 12:41:38

+0

Thnx for the回答。將來會了解更多關於硒的未來 – 2013-04-09 11:16:22

3

2年後,Ruby實現:

wait = Selenium::WebDriver::Wait.new(:timeout => 10) 
wait.util { 
    @driver.execute_script("return document.readyState;") == "complete" 
} 
+0

很酷。但目前的版本處理頁面轉換負載非常好! – 2013-08-28 04:08:12

+1

@ThiagoFMacedo我不能說Linux,但它不是我的經驗,它在Windows上處理它。我們做了類似allenhwkim建議的事情。 – 2014-01-07 13:03:12

相關問題