Modern Web Automation With Python and Selenium

SeleniumAutomation TestingTesting Tools

We can have modern web automation with Python and Selenium. To configure with Selenium webdriver in Python the steps described below need to be followed −

Step1 −To install Python in our system, visit the link − https://www.python.org/downloads/

Step 2 − Click on the Download Python <version number> button. Once the download is completed, the Python executable file should be available in our system.

Step 3 − Double-click on this executable file and the Python installation landing page should be opened. Click on Install Now.

Step 4 − Python should be available in the below path −

C:\Users\<User>\AppData\Local\Programs\Python\Python<version>

Step 5 − We shall configure the path of the folders - Python and Scripts (introduced within the Python folder) in the Environment variables for the Windows users.

Step 6 − To verify, Python has been installed, run the command: python --version. The Python version should get displayed.

Step 7 − Selenium bindings installation can be done by executing the command: pip install selenium.

Step 8 − A folder called Selenium should be found within the Python folder. To update the Selenium existing version, run the command: pip install –U selenium.

Step 9 − Finally, we should also have a Python editor - PyCharm to create the Selenium scripts((https://www.jetbrains.com/pycharm/).

Step 10 − To launch the Selenium script in a browser, we also need to download the browser drivers. For this, visit the below link − https://www.selenium.dev/downloads/

Step 11 − Scroll down to the Browser section and to download the browser drivers for different browsers.

Example

Code Implementation

from selenium import webdriver
#configure chromedriver path
driver = webdriver.Chrome(executable_path='../drivers/chromedriver')
#implicit wait
driver.implicitly_wait(0.5)
#url launch
driver.get("https://www.tutorialspoint.com/questions/index.php")
print('Page title: ' + driver.title)
#browser close
driver.close()

Output

raja
Published on 29-Jun-2021 08:27:21
Advertisements