Switch window command introduction for selenium

Selenium WebDriver Switch Window Commands

Some web applications have many frames or multiple windows. Selenium WebDriver assigns an alphanumeric id to each window as soon as the WebDriver object is instantiated. This unique alphanumeric id is called window handle. Selenium uses this unique id to switch control among several windows. In simple terms, each unique window has a unique ID, so that Selenium can differentiate when it is switching controls from one window to the other.

 

GetWindowHandle Command

Purpose: To get the window handle of the current window.

 

GetWindowHandles Command

Purpose: To get the window handle of all the current windows.

 

SwitchTo Window Command

Purpose: WebDriver supports moving between named windows using the “switchTo” method.

Or

Alternatively, you can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so:

Or

Switching between windows with Iterators:

 

SwitchTo Frame Command

Purpose: WebDriver supports moving between named frames using the “switchTo” method.

 

SwitchTo PopUp Command

Purpose: WebDriver supports moving between named PopUps using the “switchTo” method. After you’ve triggered an action that opens a popup, you can access the alert and it will return the currently open alert object. With this object you can now accept, dismiss, read its contents or even type into a prompt. This interface works equally well on alerts, confirms, and prompts.

 

Practice Exercise 1

1) Launch new Browser

2) Open URL “http://toolsqa.com/automation-practice-switch-windows/”

3) Get Window name (Use GetWindowHandle command)

4) Click on Button “New Message Window”, it will open a Pop Up Window

5) Get all the Windows name ( Use GetWindowHandles command)

6) Close the Pop Up Window (Use Switch Command to shift window)

Solution

 

 

Practice Exercise 2

1) Launch new Browser

2) Open URL “http://toolsqa.com/automation-practice-switch-windows/”

3) Click on Button “Alert Box”, it will open a Pop Up Window generated by JavaScript

4) Switch to Alert window (Use ‘SwitchTo()Alert() command)

5) Close the Pop Up Window (Use Accept command)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值