selenium automated testing small practice

Pseudo-code shows (Jilin University to achieve automatic health reporting)

from selenium import webdriver
import time
chrome_driver=r"D:\Python\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe"
driver=webdriver.Chrome(chrome_driver)
if __name__=="__main__":
    driver.get(r"https://ehall.jlu.edu.cn")
    driver.find_element_by_xpath("//*[@id='username']").send_keys("这里写vpns的用户名") 
    driver.find_element_by_xpath("//*[@id='password']").send_keys("这里写vpns的密码") 
    driver.find_element_by_xpath("//*[@id='login-submit']").click()
    driver.find_element_by_xpath("/html/body/div[1]/div[4]/ul/li[1]/a").click()
    driver.find_element_by_xpath("/html/body/div[1]/div/div[3]/div/ul[1]/li").click()
    driver.switch_to.window(driver.window_handles[-1])
    driver.find_element_by_xpath("//*[@id='V1_CTRL82']").click()
    driver.find_element_by_xpath("//*[@id='form_command_bar']/li[1]/a").click()
    time.sleep(3)
    driver.find_element_by_xpath("//*[@class='dialog display']/div[2]/button[1]").click()
    time.sleep(3)
    driver.find_element_by_xpath("//*[@class='dialog display']/div[2]/button").click()
    driver.quit()

The basic idea and used the knowledge

The program must be installed selelnium and chromedriver.exe to run, after the first with selenium start Google browser, then enter the login page, fill in the username password and click login, and then use the Google browser developer tool can easily get the node you name it the xpath, by xpath positioning element, and then fill in the information or click to simulate human operation, which used to be noted that the current web browser switch and wait for the page to update knowledge and then a small operation

Published 84 original articles · won praise 0 · Views 2014

Guess you like

Origin blog.csdn.net/qq_41985293/article/details/104561760