Saturday, October 8, 2022

Selenium setup on python and different webdrivers

Install python 3 based on the OS.

For mac, the install location of python3

mac os python3 install path:

PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"

export PATH


Then, install the selenium module (pypi.org/project/selenium/)

pip install selenium

## gets installed in <python_home>/Lib/site-packages/ on windows.

## to verify:
pip show selenium


Also configure pycharm.

ctrl+shift+enter to run the program in pycharm.

"{} {}".format("Value is",b)   ##instead of concatenating we can use format strings.


Can configure different drivers based on the webdriver selected.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

##download chrome driver for your OS and place the path of it.
## Service, responsible for setting chrome driver service
## if you don't pass chromedriver.exe path below, it download and install automatically
service_obj = Service("/Users/uday/documents/chromedriver.exe")

driver=webdriver.Chrome(service=service_obj)

driver.maximize_window()
driver.get("https://rahushettyacademy.com")
print(driver.title)
print(driver.current_url)
driver.get("https://rahushettyacademy.com/seleniumPractise/#/")
driver.minimize_window()
driver.back()
driver.refresh()
driver.forward()
driver.close()

for firefox:

service_obj = Service("/Users/uday/documents/geckodriver.exe") ##download firefox gecko driver 

driver=webdriver.Firefox(service=service_obj)

for edge:

service_obj = Service("/Users/uday/documents/msedgedriver.exe") ##download edge driver 

driver=webdriver.Edge(service=service_obj)


for IE:

service_obj = Service("/Users/uday/documents/IEDriver.exe") ##download IE driver 

driver=webdriver.IE(service=service_obj)

No comments:

Post a Comment