1 from selenium import webdriver 2 import time 3 4 driver = webdriver.Firefox() 5 driver.implicitly_wait(10) 6 driver.get("https://www.baidu.com") 7 try: 8 driver.find_element_by_id("kw1").is_displayed() #是否存在 9 # driver.find_elemen
2 import time
3
4 driver = webdriver.Firefox()
5 driver.implicitly_wait(10)
6 driver.get("https://www.baidu.com")
7 try:
8 driver.find_element_by_id("kw1").is_displayed() #是否存在
9 # driver.find_element_by_id("wyf").is_enabled() #可编辑状态
10 # driver.find_element_by_id("wbc").is_selected() #是否被选中
11 except:
12 print("元素不存在")
13 else:
14 driver.find_element_by_id("kw").send_keys("fuckyou!")
15 print(driver.find_element_by_id("kw").text)
16 time.sleep(10)
17 driver.quit()