In this article, we will share the selenium+Python automatic login script. The code is listed in this article. If you are interested in Python development, take a look.
OS: Windows
Prerequisite: Python, Selenium, iedRiverServer. exe, Ie
Start by installing Python2.7
After the installation, run the PIP install -u Selenium command on the cli
After Selenium is installed, download iedRiverServer.exe from the Selenium official website
Place iedRiverServer. exe in the installation directory of Internet Explorer: C:Program Files (x86)Internet Explorer and add this directory to the environment variables of your computer
Webdriver testing:
On the Python command line, type the command:
from selenium import webdriver
webdriver.Ie()
If Internet Explorer is opened and the message “This is the Initial start page for the WebDriver Server” is displayed, the WebDriver server succeeds
Automatic login source code:
from selenium import webdriver
import time
driver=webdriver.Ie()
The login
xxx.com
driver.get(
“http://XXXX.com
“)
Wait 10 seconds. It takes time for the browser to open and the page to jump
time.sleep(10)
Get the page element with ID txtLoginCode (username input element)
elem_user=driver.find_element_by_id(‘txtLoginCode’)
Empty the input
elem_user.clear()
Type a user name
elem_user.send_keys(‘nice_xp’)
Take the page element with ID txtPwd (password input element)
elem_pass=driver.find_element_by_id(‘txtPwd’)
Empty the input
elem_pass.clear()
Enter the password
elem_pass.send_keys(‘*’)
Take the login button with ID btnLogin
elem_login=driver.find_element_by_id(‘btnLogin’)
Click the Login button
elem_login.click()
exit(0)
Selenium +Python automatic login script
Learn more about Python at gzitcast