Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法单击元素[selenium]_Python_Python 3.x_Selenium - Fatal编程技术网

Python 无法单击元素[selenium]

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

我已经尝试了所有的方法来定位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(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