Maison > Questions et réponses > le corps du texte
登陆126邮箱时 通过几种定位都不行 真蛋疼
代码如下:
from selenium import webdriver driver = webdriver.Firefox() driver.get('http://126.com') frame = driver.find_element_by_id('x-URS-iframe') driver.switch_to.frame(frame) '''id定位 时时变因为它的ID是动态的''' driver.find_element_by_id('auto-id-1479158591510').click() '''通过类名定位也定不到''' driver.find_element_by_class_name('j-inputtext dlemail').click() '''路劲定位也定不到 ''' driver.find_element_by_xpath('//[@id ="auto-id-1479158591510"]').click()*
欧阳克2016-11-15 16:46:07
用css selector来解决这个问题,代码如下,希望能解决你的问题
from selenium import webdriver import time driver = webdriver.Chrome("/Users/lvxiang/Downloads/chromedriver") driver.get('http://www.126.com/') frame = driver.find_element_by_id('x-URS-iframe') driver.switch_to.frame(frame) # XXXX替换为你的用名和密码 driver.find_element_by_css_selector("form input[name='email']").send_keys("XXXX") time.sleep(1) driver.find_element_by_css_selector("form input[name='password']").send_keys("XXXX") time.sleep(1) driver.find_element_by_id("dologin").click() print("登录成功") time.sleep(1) driver.close()