Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

How to Handle Multiple Windows in Selenium WebDriver

Автор: H Y R Tutorials

Загружено: 2020-05-15

Просмотров: 100001

Описание:

In this video, I have shown how we can handle Multiple Windows in Selenium WebDriver.

Window handles refer to the windows or tabs which were opened by the driver instance in selenium.

Every window will have a unique string value to identify and we call that as a handle.

Selenium provides two methods to get those handle values.
1) getWindowHandle
2) getWindowHandles

==== Get window handle =====
WebDriver does not make the distinction between windows and tabs. If your site opens a new tab or window, Selenium will let you work with it using a window handle. Each window has a unique identifier that remains persistent in a single session. You can get the window handle of the current window by using:

driver.getWindowHandle();


==== Get window handles =====
You can get the window handles of the currently opened windows by using:

driver.getWindowHandles();


==== Switching windows or tabs =====
Clicking a link/button that opens in a new window will focus on the new window or tab on the screen, but WebDriver will not know which window the Operating System considers active. To work with the new window you will need to switch to it. If you have only two tabs or windows open, and you know which window you start with, by the process of elimination you can loop over both windows or tabs that WebDriver can see, and switch to the one which is not the original.

Syntax:
driver.switchTo().window(windowHandle);

Code:
//launches browser window with the mentioned URL
driver.get("https://www.hyrtutorials.com/p/window...");

//Store the ID of the parent window
String parentWindow = driver.getWindowHandle();

//Click the link which opens in a new window
driver.findElement(By.id("newTabBtn")).click();

//Loop through until we find a new window handle
for (String windowHandle : driver.getWindowHandles()) {
if(!parentWindow.contentEquals(windowHandle)) {
driver.switchTo().window(windowHandle);
driver.findElement(By.id("firstName")).sendKeys("yadagiri");
break;
}
}

==== Closing a window or tab ====
When you are finished with a window or tab and it is not the last window or tab open in your browser, you should close it and switch back to the window you were using previously. Assuming you followed the code sample in the above section you will have the previous window handle stored in a variable. Put this together and you will get:

//Close the tab or window
driver.close();

//Switch back to the old tab or window
driver.switchTo().window(parentWindow);

==============================================
************* Checkout my other playlists *************
==============================================
Java Programming videos playlist:👇
🔗 https://bit.ly/3keRJGa

Selenium WebDriver with Java videos playlist:👇
🔗 https://bit.ly/2FyKvxj

Selenium interview questions videos playlist:👇
🔗 https://bit.ly/3matUB3

Windows automation with FlaUI videos playlist:👇
🔗 https://bit.ly/33CG4dB

CSS Selectors videos playlist:👇
🔗 https://bit.ly/2Rn0IbD

XPath videos playlist:👇
🔗 https://bit.ly/2RlLdkw

Javascript Executor videos playlist:👇
🔗 https://bit.ly/2FhNXwS

Apache POI videos playlist:👇
🔗 https://bit.ly/2RrngrH

Maven videos playlist:👇
🔗 https://bit.ly/2DYfYZE

How to fix Eclipse errors:👇
🔗 https://bit.ly/3ipvNYf
==============================================
==============================================
Connect us @
🔗 Website - www.hyrtutorials.com
🔗 Facebook - www.facebook.com/HYRTutorials
🔗 LinkedIn - www.linkedin.com/company/hyrtutorials
🔗 Twitter - www.twitter.com/Hyrtutorials
==============================================
==============================================
🙏 Please Subscribe🔔 to start learning for FREE now, Also help your friends in learning the best by suggesting this channel.

#selenium #windowHandles #multipleWindows #hyrtutorials #webAutomation

How to Handle Multiple Windows in Selenium WebDriver

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

array(0) { }

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]