1 #Author:xiaoxiao 2 from selenium import webdriver 3 import time 4 5 def abcd(): 6 driver = webdriver.Firefox() 7 driver.get('http://photo.163.com') 8 # 找到登录模块对应的iframe 9 driver.switch_to.frame(driver.find_element_by_xpath("//div[@id='J-loginMod']//iframe")) 10 driver.switch_to.frame("x-URS-iframe") 11 # 找到账号输入框并输入账号 12 userinput = driver.find_element_by_name("email") 13 userinput.send_keys("123456") 14 time.sleep(2) 15 #清除输入框内容 16 userinput.clear() 17 time.sleep(2) 18 #输入用户名内容 19 userinput.send_keys("yeyll0630") 20 # 找到密码输入框并输入密码 21 pwinput = driver.find_element_by_name("password") 22 pwinput.clear() 23 pwinput.send_keys("abc123") 24 # 找到登录按钮并点击 25 loginbutton = driver.find_element_by_id("dologin") 26 loginbutton.click()
1 #Author:xiaoxiao 2 from selenium import webdriver 3 import time 4 5 def abcd(): 6 #打开浏览器 7 driver = webdriver.Firefox() 8 driver.get('http://www.baidu.com') 9 # 打印输入框尺寸 10 print(driver.find_element_by_id("kw").size) 11 # 打印信息 12 print(driver.find_element_by_id("cp").text) 13 # 打印输入框属性值 14 print(driver.find_element_by_id("kw").get_attribute("id")) 15 # 打印元素是否可见 16 print(driver.find_element_by_id("kw").is_displayed()) 17 #定位输入框 18 driver.find_element_by_id("kw").send_keys("python") 19 #提交搜索 20 driver.find_element_by_id("kw").submit()