In HTML pages, we have different kind of pop ups, we will discuss about them in this tutorial. Different popups will have different properties.
Types of Pop Ups :
We have different section for Alert and Confirmation Pop Ups, so in this page we are going to discuss how to handle remaining Pop Ups in selenium python bindings
When we open password protected pages, we tend to get Authentication pop up. Authentication pop up will have username and password fields, the UI look of the pop up may vary browser to browser
Visit URL selenium webdriver Auth : https://chercher.tech/auth, site expects you to provide credentials
username - selenium
password - webdriver
Authentication Popup :
Properties of the Authentication Pop up :
Solution to Authentication Pop Up :
We have to pass the user name and pass word along with url to handle the authentication pop in selenium python. Please find the syntax to pass the username and password
Protocols: Http, Https, Ftp,..
To Access the https://chercher.tech/auth page you need to pass username and password like below.
import unittest from selenium import webdriver class Test(unittest.TestCase): def test_authentication_popup(self): driver = webdriver.Chrome(executable_path=r'D:\PATH\chromedriver.exe'); driver.implicitly_wait(30) # open webpage driver.get("https://selenium:firstname.lastname@example.org/auth"); # verify the title if(driver.title == "Authentication Successful"): System.out.println("Test Passed"); else: System.out.println("Test failed"); if __name__ == "__main__": unittest.main()
Hidden division pop is nothing but html code which is hidden initially, hidden division pop up also known as dialog or overlay.
Overlay is triggered when application user performs certain tasks like clicking a button, submitting the form or on page load...
Handle Hidden division Pop Up :
1. Navigate to : https://chercher.tech/practice/hidden-division-popup
2. Click on View Pop-Up button
3. Application opens a Model
4. Write xpath for the Name text bar : //input[@type='text']
5. Send text for the Name, using sendKyes in selenium.
6. No Special Operation required to handle hidden division popup.
An example program for handling hidden division pop up in selenium python
import unittest from selenium import webdriver class Test(unittest.TestCase): def test_authentication_popup(self): driver = webdriver.Chrome(executable_path=r'D:\PATH\chromedriver.exe'); driver.implicitly_wait(30) driver.get("https://chercher.tech/practice/hidden-division-popup"); driver.find_element_by_class_name("cd-popup-trigger") # send text to Name field on overlay driver.find_element_by_xpath("//input[@type='text']").send_keys("Hidden Division Text"); if __name__ == "__main__": unittest.main()
Even though pop up content is present but pop is not present on UI until we click a button, for this reason, it is called as hidden division popup
Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know.
Knowledge is the only thing that doubles when you spend it.
I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation