【发布时间】:2021-03-05 01:51:01
【问题描述】:
我有一个 python selenium 脚本,它加载 Google chrome 驱动程序,然后对 URL 进行一些自动化操作。以下是我在脚本中加载驱动程序的方式:
try:
self.driver = webdriver.Chrome(options=options, executable_path=self.path)
except Exception as err:
print(str(err))
else:
print("Chrome driver Launched")
self.Login_url()
'''Login_url() and other functions defined below...
但当代码在 try 块中时(即 chrome 驱动程序仍在加载),我会弹出一些窗口消息框,如下图所示:
只有当我在所有消息框上手动单击“确定”时,控件才会到达我代码中的 else 部分,打印"Chrome driver Launched",然后进一步移动。
因此我想这样做:
在我的脚本中编写一个 python 函数,首先确定是否弹出了 windows msgbox(这很重要,因为上述消息框不会在我每次运行我的脚本时弹出)。如果识别出弹出窗口,则单击确定。
如何在以下选项中处理此问题(答案的偏好按确切顺序)
- Selenium 本身通过添加一些 webdriver 首选项/选项?
- 使用 python 的默认
tkinter包进行 Windows GUI 自动化? - 使用 python 的
pywinauto包实现 GUI 自动化?
请帮忙。
【问题讨论】:
-
我已经浏览了stackoverflow.com/questions/12450384/… 的文章。类似这样的python等价物应该会有所帮助
-
Tkinter 在这里绝对没用。
-
为什么不尝试修复 chrome 而不是开发一种关闭弹出框的方法?
标签: python windows selenium google-chrome selenium-chromedriver