Python 无法单击元素[selenium]
我已经尝试了所有的方法来定位seleniums文档中的元素,但我想不出来。谢谢你的帮助Python 无法单击元素[selenium],python,python-3.x,selenium,Python,Python 3.x,Selenium,我已经尝试了所有的方法来定位seleniums文档中的元素,但我想不出来。谢谢你的帮助 def protonmail_signup(): browser.get('https://protonmail.com/signup') time.sleep(random.randint(10,15)) free_acc = browser.find_element_by_class_name('panel-heading').click() time.sleep(rand
def protonmail_signup():
browser.get('https://protonmail.com/signup')
time.sleep(random.randint(10,15))
free_acc = browser.find_element_by_class_name('panel-heading').click()
time.sleep(random.randint(2,3))
free_elem = browser.find_element_by_id('freePlan').click()
time.sleep(random.randint(20,25))
email_elem = browser.find_element_by_id('username').click()
一切正常,除了:
email_elem = browser.find_element_by_id('username').click()
看起来
username
在iframe
元素中。您需要切换到iframe
,然后输入用户名文本:
# save main frame context so we can switch back later
main_frame = driver.current_window_handle
# Get the first iframe -- there are two
iframe = driver.find_elements_by_xpath("//iframe[@title='Registration form']")[0]
driver.switch_to.frame(iframe)
# enter email
email_elem = browser.find_element_by_id('username').click()
然后,您需要切换回主框架以输入密码:
# switch back to main frame
driver.switch_to_window(main_frame)
#enter password next
正如我在评论中提到的,有两个嵌套的iframe
元素。第一个[0]
将获得包含用户名的iframe
。第二个,您需要切换到,以便可以单击Create Account
second_iframe = driver.find_elements_by_xpath("//iframe[@title='Registration form']")[1]
driver.switch_to.frame(second_iframe)
# click Create Account button