我正在尝试使用pythonselenium安装chrome扩展。 当我点击addtochrome按钮时,会产生一个弹出窗口(不知道它是否是java脚本),询问:“addextension”,“Cancel”。我想单击“添加扩展名”,但我收到以下错误:
selenium.common.exceptions.NoAlertPresentException: Message: no alert open
我的代码:
from selenium import webdriver
import time
driver=webdriver.Chrome()
driver.implicitly_wait(30)
driver.get("https://chrome.google.com/webstore/detail/buyhatke/jaehkpjddfdgiiefcnhahapilbejohhj?hl=en")
time.sleep(15)
element=driver.find_element_by_css_selector("body > div.F-ia-k.S-ph.S-Rc-qa > div.h-F-f-k.F-f-k > div > div > div.e-f-o > div.h-e-f-Ra-c.e-f-oh-Md-zb-k >
div.dd-Va.g-c-wb.g-eg-ua-Uc-c-za.g-c-Oc-td-jb-oa.g-c")
element.click()
alert = driver.switch_to.alert
alert.accept()
帮我安装一下。在
更新代码:
^{pr2}$
这是因为您尝试使用
switch_to.alert
选择的下载选项弹出窗口实际上不是JS警报弹出窗口。您不能选择is using Selenium的switch_to
方法。您需要使用DesiredCapabilities
类来选择这个选项,然后在代码中使用它。在根据ChromeDriver文档,给定here,请使用压缩的(扩展名为
.crx
的文件)或未打包的扩展文件(包含扩展名的目录,包括manifest.json file
)并使用DesiredCapabilities
加载。可以使用相关问题 更多 >
编程相关推荐