单击带有selenium的消息按钮

2024-05-16 12:57:26 发布

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

我正在尝试通过selenium注册mail.protonmail,我将尝试用ML解决验证码问题

但我发现自己花了几个小时在一些我认为需要几分钟的事情上

在我按下创建帐户-

The message that pops

我试图只找到它的xpath/id,但似乎找不到它

它没有检测到新窗口/警报,所以我现在有点绝望

以下是html代码,如果它可以帮助您:

<button id="confirmModalBtn" autofocus="" class="pm_button primary modal-footer-button">Confirm</button>

我所做的是:

web = webdriver.Chrome(executable_path=r"D:\geckodriver \chromedriver.exe")
web.get(r'https://mail.protonmail.com/create/new?language=en')
# filling the data and getting to message i posted above..
accept_ele = web.find_element_by_class_name('pm_button primary modal-footer-button') # doesnt work
accept_ele = web.find_element_by_xpath('/html/body/div[1]/form/div[2]/button[2]') # doesnt work

Tags: webidmessagehtmlbuttonmailxpathclass
2条回答

问题是我忘了切换回默认帧

别忘了换回来

您可以尝试调用WebDriverWait并使用按钮的ID在此处定位元素:

from selenium.webdriver.support import expected_conditions as EC

accept_ele = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='confirmModalBtn']")))

我导航到你发布的网站,并复制了你在截图中显示的弹出窗口。我能够使用上面提供的XPath定位元素:

enter image description here

相关问题 更多 >