Thursday 6 May 2021

Why Selenium using Python?

 Why Selenium using Python?

There are n number of reasons to learn selenium using python

  • Python is open source and lots of packages are available on internet which can be utilized in your framework.
  • Python is easy to learn if you know any basic programming language.
  • writing code in python is also simpler than any other languages
  • Industry is moving towards python and hence learning automation framework using python would add value.

 Let us start with selenium with python and slowly we will build a pytest framework using this

Which editor to use for coding?

I have used pycharm as it is easy to write code here and to debug. You can download from below link

https://www.jetbrains.com/pycharm/download/

How to install selenium?

Use below command for installing selenium on your machine

pip install selenium

Once selenium is installed on your machine you would see

C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Scripts>pip install -U selenium
Collecting selenium
  Using cached selenium-3.141.0-py2.py3-none-any.whl (904 kB)
Requirement already satisfied, skipping upgrade: urllib3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from selenium) (1.25.8)
Installing collected packages: selenium
Successfully installed selenium-3.141.0

To check whether selenium package is installed or not please check below url on system 

C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Lib\site-packages

You should be able to see the selenium packages if properly installed.

How to invoke chrome browser in your selenium?

from selenium import webdriver

driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")

chromedriver could be found from below url

https://chromedriver.chromium.org/downloads

Unzip the folder and later paste the chromedriver.exe at any location which you can invoke in your program.

Some basic webdriver methods


from selenium import webdriver

driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.get("https://mobile-automation-testing.blogspot.com/p/adb-command-to-send-sms.html")
driver.maximize_window()
print("Page Title : " + driver.title)
print("Current URL : " + driver.current_url)
print(driver.name)
driver.back()
driver.refresh()
driver.minimize_window()
driver.close()

driver.get will get the url which need to be automated

driver.maximize_window would maximize the chrome window

driver.title would get the webpage title

driver.name would get the name of browser

driver.back() would get back to the previous page

driver.refresh() would refresh the current webpage

As there are many methods under webdriver you would know each by learning further in this blog

Inspecting HTML to identify attribute of elements


No comments:

Post a Comment

Different type of locators in webdriver selenium

 Webdriver locators ID This can be used when you know the id attribute of an element. If the element is not found by mentioned attribute, it...