登录页脚本小结

获取元素:by_xpath
页面元素等待:WebDriverWait
 1 from selenium import webdriver
 2 from selenium.webdriver.common.by import By
 3 from selenium.webdriver.support.ui import WebDriverWait
 4 from selenium.webdriver.support import expected_conditions as EC
 5 
 6 from selenium.webdriver.common.action_chains import ActionChains
 7 
 8 dr = webdriver.Firefox()
 9 dr.get("http://140.143.21.109:3000/index/login")
10 title = dr.title
11 print(title)
12 dr.find_element_by_xpath("//input[@name='username']").send_keys("admin")
13 dr.find_element_by_xpath("//button[@class='btn btn-submit btn-primary']").click()
14 
15 ele = WebDriverWait(dr,2,0.2).until(
16     EC.presence_of_element_located((By.CLASS_NAME,'layui-layer-content'))
17 )
18 aaa = dr.find_element_by_xpath("//*[@class='layui-layer-content']").get_attribute("textContent")
19 
20 #aaa = dr.find_element_by_xpath().get_attribute('textContent')
21 print("aaaaaaaaaaaaaaaaaa")
22 print(aaa)
原文地址:https://www.cnblogs.com/wbw-test/p/11507101.html