셀레늄 자동화 된 테스트 작은 실천

의사 코드 쇼 (길림 대학은 자동 상태보고를 달성하기 위해)

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()

기본 개념과 지식을 사용

이 프로그램은 구글의 브라우저를 시작 selelnium을 설치하고 셀레늄을 가진 후 처음 실행하는 데 chromedriver.exe해야하고 사용자 이름 암호 로그인 페이지 채우기를 입력하고 로그인을 클릭하고 당신이 그것을 노드의 이름을 쉽게 얻을 수있는 구글 브라우저 개발자 도구를 사용하여 XPath는 위치 요소로 XPath는, 다음 정보를 입력하거나주의해야하는 데 사용되는 인간의 동작을 시뮬레이션합니다 그 다음 업데이트 지식 페이지와 작은 작업에 대한 현재의 웹 브라우저 스위치와 대기

게시 84 개 원래 기사 · 원의 칭찬 0 · 조회수 2014

추천

출처blog.csdn.net/qq_41985293/article/details/104561760