Handle GOOGLE Browser Windows in Selenium |
Автор: Code Peddi
Загружено: 2023-10-10
Просмотров: 28
Описание:
#selenium #automation #manualtesting
In this video, I explained how to switch to specific windows when dealing with multiple open windows and how to handle multiple child windows in Gmail.
Handling multiple browser windows or tabs in Selenium WebDriver involves several methods to navigate, switch between, and manage them. Below are common methods and techniques for handling windows in Selenium:
1) getWindowHandles(): This method retrieves a set of unique identifiers (window handles) for all currently open windows or tabs. Each window handle corresponds to a different browser window or tab.
Set(String) windowHandles = driver.getWindowHandles();
2)getWindowHandle(): This method returns the handle of the currently focused window, typically the parent window that was first opened.
String parentHandle = driver.getWindowHandle();
3)switchTo().window(handle): To switch between windows or tabs, you use the switchTo().window(handle) method, where handle is the window handle you want to switch to. This allows you to interact with elements in the target window.
driver.switchTo().window(handle);
4)Iterate through Multiple Windows: You can iterate through multiple windows or tabs by first getting all window handles and then switching to each window one by one.
Set (String) windowHandles = driver.getWindowHandles();
for (String handle : windowHandles) {
driver.switchTo().window(handle);
}
5)Switch Back to the Parent Window: After performing actions in a child window or tab, you can switch back to the parent window using its handle.
driver.switchTo().window(parentHandle); // Switch back to the parent window
6)Handling Pop-up Windows: For pop-up windows (e.g., alerts, confirmations), you can use switchTo().alert() to interact with the alert.
Alert alert = driver.switchTo().alert();
alert.accept();
7)Window Titles: You can use driver.getTitle() to get the title of the current window.
String windowTitle = driver.getTitle();
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: