Python Selenium找不到提交按钮

2024-05-16 17:39:22 发布

您现在位置:Python中文网/ 问答频道 /正文

链接:https://mail.protonmail.com/create/new?language=en

问题

chrome.find_element_by_xpath("//input[@type='submit']").click()

Python在HTML代码中找不到submit按钮id、名称或类

HTML:

<button type="submit" class="btn btn-submit" name="submitBtn">Create Account</button>


Tags: httpscomnew链接htmltypecreatebutton
1条回答
网友
1楼 · 发布于 2024-05-16 17:39:22

首先,您需要切换到包含提交按钮的iframe。您可以找到它并提交

from selenium import webdriver
import os
import time

browser = webdriver.Chrome(executable_path =os.path.abspath(os.getcwd()) + "/chromedriver")
browser.get("https://mail.protonmail.com/create/new?language=en")
# wait page to load
time.sleep(3)
# find iframe
iframe = browser.find_element_by_css_selector('iframe[data-name="bottom"]')
# switch into iframe
browser.switch_to.frame(iframe)
browser.find_element_by_class_name('btn.btn-submit').click()

相关问题 更多 >