Web Alert are used to confirm the action taken by the user.
It take the focus away from the current window , and force the user to read the alert message.
Generally Web alerts consist of message and an OK, CANCEL button.
How does Selenium WebDriver handle Web Alert ??
In selenium WebDriver when an alert appears in the web-page ,
the control is still in the web-page hence we have to switch the control from
the web-page to alert window.
For accessing the Web Alert , we first have to create an alert object.
alert = browser.switch_to_alert()
Now we have control over the alert.
To perform action on the alert we need to know about alert class.
What is a Alert Class??
With the help of Alert Class we can interact with alerts.
With this class we can
accept the alert using accept()----method
reject the alert using dismiss()-----method
enter value in the alert box using send_keys()-----method
receive the text found in the alert using ".text"
It take the focus away from the current window , and force the user to read the alert message.
Generally Web alerts consist of message and an OK, CANCEL button.
How does Selenium WebDriver handle Web Alert ??
In selenium WebDriver when an alert appears in the web-page ,
the control is still in the web-page hence we have to switch the control from
the web-page to alert window.
For accessing the Web Alert , we first have to create an alert object.
alert = browser.switch_to_alert()
Now we have control over the alert.
To perform action on the alert we need to know about alert class.
What is a Alert Class??
With the help of Alert Class we can interact with alerts.
With this class we can
accept the alert using accept()----method
reject the alert using dismiss()-----method
enter value in the alert box using send_keys()-----method
receive the text found in the alert using ".text"
Simple Alert Button
Lets handle a simple alert.In order to generate alert please copy the below html code,
and save it in ex1.html .
Lets handle a simple alert.In order to generate alert please copy the below html code,
and save it in ex1.html .
Navigate to folder where the file is saved and double click it.
The browser open with
Now before we write test scripts lets write test cases.
test_ex1.html
Output in window's command prompt
Alert with OK & CANCEL Buttons
Save the below code in ex2.html
When we open ex2.html in a browser we get
The Test Cases for ex2.html are
test_ex2_v1.py
Lets us run test_ex2_v1.py in command line.
Now let us put the ConfirmationTestCase class in a file called ex2Base.py
Let us retain ConfirmationTest and save the file as ex2Test.py
lets us run ex2Test.py from window command line.
Dialogue Box
Please copy the below code for generating a dialogue box as show above.
Now lets write the test cases
test_ex3.py
Now lets execute test_ex3.html from window command line,