The core of the key is to compare the changes in the page before and after
- Code version 1
-
# coding=utf-8#
#导入webdriver模块
From selenium import Webdriver
From time import sleep
# Webdriver Local directory, specified to exe
Execute_path = R ' C:\Program Files (x86) \google\chrome\application\chromedriver.exe '
Equal_string= ' 2016? Nanjing Old man Jia Intelligent Technology Co., Ltd.
# Specify a driver for Chrome
# when we get here, selenium will go to the specified path and run the Chrome driver program.
Driver=webdriver. Chrome (Execute_path)
# Use the Get method to open the specified Web site
Driver.get (' http://itest.chinacloudapp.cn:8280/')
# Get the elements above the page find_element_by_id_xxx
#· Text gets the literal of the element
# Analog Login operation
# get positioning, enter values
Login_url=driver.current_url
driver.find_element_by_id (' UserName '). Send_keys (' ly ')
driver.find_element_by_id (' password '). Send_keys (' [Email protected]# ')
#查询包含doLogin的字符
Driver.find_element_by_css_selector (' button[onclick*= ' Dologin "] '). Click ()
# implicit waiting
Sleep (2)
# driver.implicitly_wait (10)
# Cookies=driver.get_cookie ()
#
# Print Cookies
Homepage_url=driver.current_url
If Homepage_url==login_url:
print ' Login failed '
Else
print ' Landing success '
# Check version information
Try
Ele=driver.find_element_by_class_name ("Copyright"). Text
Print Ele
# When using text comparison, you need to consider the encoding
if ele = = Equal_string.decode (' Utf-8 '):
print ' Version information correct '
Else
print ' Version information error '
Except
print ' Version information error '
Driver.close ()
Python Login Script