Utilicé Firefox Driver para abrir dos URL. Cada vez que invoco el controlador, se abre una nueva ventana de Firefox. Tengo que cambiar entre estas dos ventanas. ¿Cómo puedo hacer esto?Cambiar entre dos ventanas del navegador utilizando Selenium WebDriver
9
A
Respuesta
19
puede utilizar el código siguiente para cambiar entre ventanas basado en el título de la ventana
private void handleMultipleWindows(String windowTitle) {
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) {
return;
}
}
}
De manera parecida se puede utilizar URL o algún otro criterio para cambiar de ventana.
2
He añadido el alcance de volver a mainWindowHandle también.
Puede probar el uso de la siguiente función siempre que esté manejando ventanas con diferentes títulos.
private String mainWindowsHandle; // Stores current window handle
public static boolean swithToWindow(WebDriver driver,String title){
mainWindowsHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles(); // Gets all the available windows
for(String handle : handles)
{
driver.switchTo().window(handle); // switching back to each window in loop
if(driver.getTitle().equals(title)) // Compare title and if title matches stop loop and return true
return true; // We switched to window, so stop the loop and come out of funcation with positive response
}
driver.switchTo().window(mainWindowsHandle); // Switch back to original window handle
return false; // Return false as failed to find window with given title.
}
Cuestiones relacionadas
- 1. ¿Cómo comunicarse entre dos ventanas del navegador?
- 2. Obtener la versión del navegador usando Selenium webdriver
- 3. Cómo cambiar entre fotogramas en Selenium WebDriver usando Java
- 4. Cómo obtener la sesión del navegadorId utilizando Selenium webdriver
- 5. Selenium WebDriver cómo cerrar el navegador emergente
- 6. Localizador del navegador de prueba con Selenium webdriver
- 7. Ejecute JavaScript utilizando Selenium WebDriver en C#
- 8. Pruebas automatizadas del navegador utilizando selenio, Nunit, Selenium Grid, C#, webdriver/control remoto
- 9. Manejo de ventanas emergentes del navegador con Selenium
- 10. Diferencia entre Selenium RC y WebDriver
- 11. Selenium Webdriver configuración remota
- 12. Amplíe Selenium WebDriver WebElement?
- 13. Comprobación de texto de marcador de posición utilizando Selenium Webdriver
- 14. Desplazamiento con Selenium WebDriver con Java
- 15. Azure SDK 1.3 abre dos ventanas del navegador (o pestañas)
- 16. ¿Cómo puedo cambiar entre dos fotogramas con Capybara
- 17. ¿Cómo se comunica entre 2 pestañas/ventanas del navegador?
- 18. Selenium WebDriver objeto de página
- 19. ¿Es posible arrastrar y soltar contenido entre dos ventanas del navegador usando JQuery u otro método?
- 20. ¿Cuál es la relación entre Selenium RC y WebDriver?
- 21. Selenium WebDriver Find nth element
- 22. Prueba autocompletar con Selenium webdriver
- 23. elemento selectivo de Selenium webdriver
- 24. Selenium 2 (WebDriver) o Geb?
- 25. Maximice WebDriver (Selenium 2) en Python
- 26. Selenium WebDriver para seleccionar el elemento del cuadro combinado?
- 27. Formato JUnit en WebDriver vs WebDriver Respaldado
- 28. setSpeed en Selenium WebDriver usando Ruby
- 29. Patrón de fábrica para Selenium webdriver
- 30. Selenium: Ventanas emergentes de prueba
Gracias, funcionó para mí. :) –
yo también! muy buen método de hacer esto – sircapsalot