Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium python javascript弹出窗口_Javascript_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium python javascript弹出窗口

Selenium python javascript弹出窗口,javascript,python,selenium,selenium-webdriver,Javascript,Python,Selenium,Selenium Webdriver,我正在使用Python中的Selenium导航到一个网站并填写表单。代码中有一部分允许您单击按钮,使用javascript打开弹出式节点树。我可以使用以下代码单击按钮: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Ie("C:\\IEDriverServer.exe") driver.get('htto://someurl.com') popup

我正在使用Python中的Selenium导航到一个网站并填写表单。代码中有一部分允许您单击按钮,使用javascript打开弹出式节点树。我可以使用以下代码单击按钮:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Ie("C:\\IEDriverServer.exe")
driver.get('htto://someurl.com')
popup = driver.find_element_by_xpath('//a[@onclick and @href = "javascript:;" and img/@alt = "Node Tree"]')
popup.click()
driver.switch_to.alert

此时,无论是在弹出框中还是在实际站点上,网站上的所有内容都变得不可访问。这是什么原因造成的?不幸的是,我无法共享Javascript,因为它是我公司的内部版本。

与其将\u切换到.alert,不如将drv.switch\u切换到\u alert 其中drv是您的驱动程序实例

在python源代码中,我看不到任何通过grepping(看起来像是切换到)可以立即看到的东西。支持语法


我本来会发表评论的,但我没有这样的名声。

你试过driver.switch_to.alert吗?@alecxe我刚刚在原来的帖子中添加了这句话。当我试图点击任何东西时,我仍然会看到黑色的圆圈,上面有一条线穿过它,这意味着我不能点击任何东西。我不知道为什么通过Selenium单击该按钮与手动单击按钮有什么不同。此外,这不是一个真正的弹出窗口,因为它不是一个单独的窗口。运气不好。PyCharm实际上推荐了这个开关。