Skip to main content

Python automation with selenium.

Automate with selenium

In this blog we are going to see how to automate some task with selenium.

Selenium is an opensource framework which is used for testing web application by scrapping into the web site.

To apply selenium in python for testing an application we need to follow some step.

So in these this blog we are going to explain how to use selenium to go to the google and search for shotwithcode blog and read the blog.

Step1: using pip in python we have to install selenium "pip install selenium"

Step2: We need a web driver in which it will run the browser and tell the browser what to do.

So if we use chrome we need to download chrome driver else if we use other browser then we need to download the web driver for that browser

You can download the Chrome web driver here https://chromedriver.chromium.org/downloads

Remember to download the chrome driver related to the chrome version we have

Step3:After download the driver extract the file and save into a location which is easy to access i prefer to save in C drive

Step4:So now we have installed everything needed for our  project so now we need to right code to perform the task

Code:

  1. from selenium import webdriver
  2. PATH = "C:/chromedriver"
  3. driver = webdriver.Chrome(PATH)
  4. driver.get('https://www.google.com')
  5. search = driver.find_element_by_name('q')
  6. search.send_keys('shotwithcode.blogspot.com')
  7. clic_k = driver.find_element_by_xpath('/html/body/div[2]/div[2]/form/div[2]/div[1]/div[3]/center/input[1]')
  8. click_k.click()
  9. next = driver.find_element_by_xpath('/html/body/div[7]/div[2]/div[10]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/div[1]/a/div/cite')
  10. next.click()
  11. read = driver.find_element_by_xpath(' /html/body/div[1]/div[2]/div[1]/div/div/main/div/div[1]/div/div/div[2]/div/div[3]/div[2]/a')
  12. read.click() 

Let us talk about the line of code we wrote

So PATH is the path of the chrome driver which you have store the chrome driver

Line3: It open the chrome browser

Line4: After opening the browser it will go to google.com

Line5: Here we use find_element_by_name to get the input field we can get this by inspecting the element

Line6: send_keys actually filling the input field

Line7: It is to find the element here i use xpath because xpath will give you the actual element

Line8: Click is use to click the button or link 

Try this code in your system and let me know about your code, you can do what ever you want whit this code.

Conclusion:

We saw that we search the shotwithcode blogspot and read the blog with out doing it manually instead python selenium did it for us.This is one of the method to test the website which we have built, if we have built any website we can test the website with selenium framework.

Let me know what you think about this project, i always welcome to any suggestion or feedback.


Comments

Popular posts from this blog

Best office computer accesories

 Here are some of the best computer accesories for your office at an affordable price in India. 1. Oxyura Gaming Mouse Pad Click here to see the Mouse pad https://amzn.to/3pVY8KL 2. Zebronics Zeb-Alex Wired Usb optical mouse Click here to see and buy the Mouse https://amzn.to/3ILT2t6 3. Usb wired keyboard Click here to see and buy the keyboard https://amzn.to/3mmzjqv 4.Laptop stand Click here to see and buy the laptop stand https://amzn.to/3dTgkih All link are from amazon so go ahead and check it out it is at an afordable price.

Top 5 mistake i made as a computer science engineer.

Top 5 mistake i made as a computer science engineer In this blog i will walk you through my mistake as a computer science engineer Yes as a person we make a lot of mistake and for me as a computer science engineer i have made a lot of mistake but in this blog I'm going to share my top 5 mistake. 1. Involve in a tutorial hell Tutorial hell is a way of learning in which we get stuck in a tutorial without learning outside of the tutorial, it is like learning from the tutorial and build the exact same project which the instructor have taught us and also it may be just copy and paste the code, after completing the tutorial we start another tutorial and repeat the same thing again and again, without adding our feature to the project or build it without any help from the instructor. 2. Trying to learn everything Yes as a computer science engineer student i try to learn everything and it is a huge mistake because i learn a bit of python and then jump to javascript and then a bit of javascr...

Python programe to find the factorial of a number

 Python program to find the factorial of a number Factorial number of a number is a product from 1 to the number which is from 1 to n where n is the number Example : factorial of 5 = 1*2*3*4*5 = 120 Code: #function to find factorial number def facto(n):     factorial = 1     for i in range(1,n+1):         factorial = factorial * i     return factorial #Take the input from the user and store in n n = int(input()) if n == 0: #factorial of 0 is always 1     print(1) else:     print(facto(n)) #other than 0 we have to find the factorial number by calling the function Input : 5 Output : 120 There is another method to find factorial number using recursion. Feel free to check the code in a code editor and try it out and also i am welcome to any suggestion. Here is the previous post : https://shotwithcode.blogspot.com/2020/12/python-automation-with-sele...