How to Handle Alerts & Select with Selenium in Python

While Testing web application, We generally encounter Alert box, Select drop downs. Let’s see How we can handle them with selenium web driver in python.

 

Generally, JavaScript popups are generated by the web application and hence they can be easily controlled by the browser.

Case1: Handling the Alert/Pops:

Create a Selenium Project and in the test Method write the below code to handle the Alert box/Pop. Just get the element using the
”find element by xpath method” and use

 

Case2: Handling the (Select)DropDown:

Create a Selenium Project and in the test Method write the below code to handle the select dropdown. Just get the element using the
”find element by xpath or id method” and use

 

 

Case3: Handling the Window Frame:

Lets assume that, When you click on button1(id=’button1’) on the main window a new window pop opens and you have switch to that window and click the button(id=’window1_button2’) on it.

 

We will learn about how to use Action chain with Selenium in Python in next tutorial.

Check out the Ultimate guide to Cross Browser Testing.

4 thoughts on “How to Handle Alerts & Select with Selenium in Python”

Leave a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.

7 Shares
Share6
Tweet
Pin1