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 :
- Selenium WebDriver (Link is given below)
- Python3
- Any Text Editor
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
# 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.
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.





Precisely explained...well done bro✨💖✨... knowledgeable
ReplyDeleteThank you so much bro ❤️❤️❤️❤️❤️✨
Delete