python - 单击带有 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?
解决方案
我提供了一个 使用 chrome with selenium for python 打开应用程序的答案,它可能对你有帮助。
推荐阅读
- excel - 我的部分代码存在问题 - 用于构建表格
- mongodb - 仅当不为空时才插入字段
- excel - 在 VBA 中循环命名范围的更快方法
- javascript - 尝试使用 webpack ignorePlugin 从最终包中删除“react-hot-loader”
- javascript - JavaScript - 函数在 IE 中抛出错误,但在 Chrome、Firefox 等中运行良好
- heroku - 我可以使用 Heroku 创建网站构建器吗?
- css -
- 不占用侧边栏的整个宽度
- typescript - 如何声明对象或对象数组?
- angular - 是否可以在打字稿文件中定义一个 ng-template?
- python - 如何使用带有文本列表的scrapy