当用selenium定位方法定位的元素在Ifram以下时,需要先切换到目标Ifram,然后在执行元素定位。比如QQ问卷登陆窗口.
driver.switch_to.frame("QQLoginIframe") driver.find_element_by_id("switcher_plogin").click() time.sleep(5) driver.find_element_by_id("u").clear() driver.find_element_by_id("u").send_keys("xxxx") driver.find_element_by_id("p").clear() driver.find_element_by_id("p").send_keys("xxxx") time.sleep(5) driver.find_element_by_id("login_button").click() time.sleep(5) driver.find_element_by_id("login_button").click()