获取元素:by_xpath
页面元素等待:WebDriverWait
![](https://kshttps0.wiz.cn/ks/note/view/39829b70-da07-48d7-a69f-4f084f33f2dd/65ac30ca-67f9-4ca5-b209-5747636f6756/index_files/71cf496e-f6cd-45d2-b5e6-d37a79dbf8f8.jpg)
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)