首页 > 解决方案 > 单击带有 Selenium 的 WhatsApp 弹出窗口

问题描述

我想单击(或按 Enter)按钮以允许 WhatsApp API 打开应用程序

在此处输入图像描述

我已经尝试了所有方法来单击或输入输入,但是到目前为止我看到的所有 selenium 函数都需要一些东西来识别元素,这似乎不适用于 HTML 中的这个特定弹出窗口。

到目前为止,我尝试过的是:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By

driver = webdriver.Chrome('./chromedriver')
driver.get("https://api.whatsapp.com/send?phone=573111111111")
time.sleep(2)
element = driver.find_element(By.XPATH, '//button[text()="Open WhatsApp"]')
element.click()
driver.switch_to_alert().accept()
#selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()="Open WhatsApp"]"}

这适用于正常的弹出窗口,但在这种情况下不适用。也许问题是这个弹出窗口不是 HTML 的一部分,而是谷歌浏览器的一部分,在这种情况下,我该如何选择这样的窗口并按 enter/click?

标签: pythonpython-3.xseleniumselenium-chromedriverwhatsapp

解决方案


我提供了一个 使用 chrome with selenium for python 打开应用程序的答案,它可能对你有帮助。


推荐阅读