2011-05-30 11 views
8

Estoy tratando de automatizar un caso de prueba donde presento el formulario haciendo clic en una imagen.¿Cómo espero a que se cargue una página después de que se envíe un formulario en Webdriver? Estoy usando el controlador de firefox

Después de las actualizaciones de las páginas que no soy capaz de interactuar con cualquier elemento de la página web

estoy usando java, conductor Firefox.

El código se atasca y no es capaz de identificar el elemento en absoluto.

¿Hay algún mecanismo de espera con el controlador web como el que hay con QTP, selenio?

Respuesta

-2
+0

supongo waitForPageLoad se utiliza cuando se está utilizando RC selenio. ¿Cuál es el caso con Webdriver? Estoy usando el controlador de Firefox .... intenté y error y parece que no hay necesidad de escribir nada cada vez que enviamos un formulario. alguien puede por favor comentar – SK176H

+0

Ver http://stackoverflow.com/questions/10720325/selenium-webdriver-wait-for-complex-page-with-javascript-to-load – reinierpost

0

Creo que con el selenio 2, usted no tiene que esperar después de presentar un formulario utilizando WebDriver Firefox.

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

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

Si el contenido es cargado por el javascript, después de cargar la página, se puede hacer algo como esto para el contenido

 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

Si Selenium 2 esperará después del 'clic () 'depende de cómo se carga la página. – reinierpost

+0

Creo que una excepción te sacará del ciclo de tiempo. No creo que esto funcione. Necesita usar WebDriverWait con el método .ignoring. – djangofan

3

Sólo tiene que utilizar FluentWait clase:

/** 
* 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")); 
*  } 
* }); 
* 

o WebDriverWait.

+0

¿Es esta una nueva clase? Tengo 2.39 (de los enlaces C#) y parece que no está allí. ¿De qué viene esto? Tal vez me falta un –

-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 tiene sus métodos para esperar implícita y explícitamente: [aquí] (http://seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits) –

+0

Thnx for the responder. Aprenderá más sobre el selenio en el futuro –

3

2 años más tarde, la implementación de rubí:

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

Cool. ¡Pero la versión actual maneja muy bien la carga de transición de página! –

+1

@ThiagoFMacedo No puedo hablar por Linux pero no es mi experiencia que lo maneje bien en Windows. Hacemos algo similar, sugirió allenhwkim. –

Cuestiones relacionadas