Skip to main content

Automate Login with Selenium Webdriver Using Python3 [2019]

Automate Login with Selenium Webdriver Using Python3 2019

Wanna do all those crazy automation stuffs you have always dream of? Start my doing this :

Requirements :

  1. Selenium WebDriver (Link is given below)
  2. Python3
  3. Any Text Editor
Let's start with the selenium web driver, what is it?
I won't bore Y'all with the technical stuff, just keep in mind that this is like a driver that has the ability to automate everything on the web. 
You can download it via this link-
https://www.seleniumhq.org/download/
[Choose python]
Or you can download the unofficial chromedriver file via this:
https://sites.google.com/a/chromium.org/chromedriver/downloads
How do you choose the correct version?
Goto- chrome://settings/help check your chrome version
Now that you have done the basic setup let's get started. 
Keep the ChromeDriver file in the same folder you'll be creating your program. 

Before you code or copy-paste this code, please understand the code.

Now let's see the code: 

from time import sleep 
from selenium import webdriver 
# This will locate and call your ChromeDriver 
browser = webdriver.Chrome('./chromedriver')
# get() function redirects your browser to the link you provide 
# here we provide the instagram login site browser.get('https://www.instagram.com/accounts/login/?hl=en')
# This gets the element name i.e your username field. 
# We'll learn how to do this later (If you are curious)
username = browser.find_element_by_name('username') 
# Now we click that ,virtually ofcourse. username.click() 
# send_keys() is like typing words on the element username.send_keys('rahul.bhatt18')
# Same goes for Password Field 
password = browser.find_element_by_name('password') password.click() password.send_keys('putYourPassword')
# click on submit button 
username.submit()
sleep(100)
browser.close()

Now run the program in your terminal or use your IDLE (PyCham) using this command :
python3 filename.py

Vola! Your automatic login system is ready!

Now if you want to learn web scrapping (getting a web element from the DOM), follow me:
If you are a web developer you can catch on easily, but for someone who has no idea about web development don't worry, I've got your back! 
This part you have to do manually for scraping the web elements from the DOM so that your WebDriver chooses the correct elements. Now I have done it so the code will work regardlessly, this is just for you to understand so that you can make some more things with this.

Now open the Instagram login site and press F12. You see the good ol' inspect element editor.

Then select this:
Then you move your cursor to the username field :
Now see the selected text in the Inspect Element :
check for 'name' attribute in the input class.

Similarly, do for the password field.
And that's how you Scrape a web element.

I m grateful , thanks for reading :)

Comments

  1. Precisely explained...well done bro✨💖✨... knowledgeable

    ReplyDelete
    Replies
    1. Thank you so much bro ❤️❤️❤️❤️❤️✨

      Delete

Post a Comment

Popular posts from this blog

How to use Chess com API using Python

  How to use Chess com API using Python Chess is an amazing strategy-based game and if you have been following the recent boom of online chess then welcome to the chess club. Online chess is amazing since it allows you to play with a random stranger at your level or stockfish (computer). There are many popular online chess websites like lichess.org, chess.com, playchess.com, and newly created kasparovchess.com. Today we will be seeing how to use chess.com API for getting players' stats. You can create software and get affiliates from them (check out the link below), so share it with them if you are planning to create something. Before you start make sure you have the following things: Pre-requirements Postman Anaconda or mini conda or Python idle Any text editor of your choice Pretty good? Now let’s download the JSON file that chess com developers have already made for us from here and then you import it to the Postman. This just helps you with prewritten get methods so that ...

First Repeating Element | Easy | Techgig

First Repeating Element | Easy | Techgig C++ Solution First Repeating Element | Easy | Techgig C++ Solution The first repeating element is the problem that comes under the Linear Search problem under the Algorithm section. Linear Search or sequential search is a method for finding an element within a list. The algorithm works by selecting and checking each number sequentially until matched. A linear search runs in at the worst linear time and makes at most n comparisons, where n is the length of the list. If each element is equally likely to be searched, then the sequential search has an average case of (n+1)/2 comparisons, but the average case can be affected if the search probabilities for each element vary. The complexity of the linear search is as follows: The basic linear search algorithm has the following steps: Given a list L on n elements with values L0…Ln-1, and target value T, to find the index of the target T in the list L. Set i to 0. If Li = T , the search te...

Data Scraping with Python 2020

Are you a regular coursera user? If yes, then you might like this python program. You can actually use the same program for similar course websites like edx, alison, udemy, etc. So, let’s start. If you have some experience with python and BeautifulSoup then you already have everything you need so make your own. The ones that don’t, follow along. Install python for your operating system. After that install requests and BeautifulSoup like this: After that, lets import the modules, and make a variable to store the url: from bs4 import BeautifulSoup import requests baseUrl = “https://www.coursera.org” Now, take an input from cli or initialize it: skillset = input().split(“ “)  Now, we’ll see the query url for the search input: example: java Fig.1. Search field in a course website Fig.2. Check the url and find a pattern So, the important part is the after the “query=” part. So, we will append the input from the user here. skillset= “%20”.join(input().split(“ “)) courseraUrl = “https://...