Selenium + Python:Microsoft Edge 警报 - 没有此类警报
Selenium + Python: Microsoft Edge Alert - no such alert
当 运行 Selenium 上的一个进程时,我得到一个弹出窗口(这似乎是 Edge 浏览器的本机)。尝试以下操作时:
browser.switch_to.alert.accept()
、
我收到错误
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
我已经尝试等待一段时间让弹出窗口出现,并且尝试使用 Edge 选项无济于事。
我必须的另一个想法是模拟按下左箭头键然后在弹出窗口激活时输入,但是我需要 select selenium 上的特定元素并且找不到弹出窗口。
from msedge.selenium_tools import Edge, EdgeOptions
options = EdgeOptions()
options.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
browser = Edge(options=options)
也许这是另一种类型的警报?
options.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
您正在启用通知将其更改为 2 或完全删除它
此外,警报仅适用于通过 windows.alert()
抛出的警报
看到的警报来自 chrome 或浏览器,而不是网站本身。所以你不能使用 switch 来提醒
不太确定,但也许浏览器不信任该程序并需要用户的许可 - 所以它不允许您使用该程序接受。
你的键模拟想法可能有效,使用键盘库,我很确定它是默认的,它可能不是,
并模拟您的按键,希望对您有所帮助。
我现在明白了为什么你最初在这个问题上提供了 50 点赏金,因为通过 Selenium 解决它是一个非常复杂的问题。
已解决 -- 2021 年 2 月 5 日
这应该不是这么难解决的!!我对多个论坛上关于此问题的所有帖子感到非常惊讶。解决这个问题需要很多线索和错误。
第 1 步:
打开 Microsoft Edge 并导航到调用对话框的站点,如下所示。
第 2 步:
选中复选框 - 允许在关联的应用程序中打开此类链接。单击“打开”。关闭关联的应用程序并关闭 Microsoft Edge。
第 3 步:
重新打开 Microsoft Edge 并导航至 edge://settings/content/applicationLinks
现在允许应用程序(例如,缩放)自动打开。
第 4 步:
关闭 Microsoft Edge 并使用以下代码启动 Selenium:
from msedge.selenium_tools import Edge
from msedge.selenium_tools import EdgeOptions
edge_driver = '/usr/local/bin/msedgedriver'
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument("user-data-dir=/Users/user_name/Library/Application Support/Microsoft Edge/User Data")
edge_options.add_argument("profile-directory=Profile 1")
edge_options.add_experimental_option("useAutomationExtension", False)
edge_options.add_experimental_option("excludeSwitches", ['enable-automation'])
# I needed this to work on macOS
edge_capabilities = edge_options.capabilities
edge_capabilities["platform"] = "ANY"
edge_capabilities.update(edge_options.to_capabilities())
driver = Edge(executable_path=edge_driver, options=edge_options)
driver.get("https://zoom.us/j/000-000-000")
缩放应用程序将在没有对话框的情况下自动打开。
似乎 msedge 或 selenium 每次启动时都会创建一个新的配置文件,这种情况仍然发生,但现在正在继承配置文件 1 的参数。
更新 -- 2021 年 2 月 4 日
根据大量研究,似乎 这个对话框 不能 在 Selenium 时处理正在控制 Google Chrome、Microsoft Edge 或 Mozilla Firefox。
可以使用多种方法在 Selenium 之外抑制该对话框,包括 Microsoft 平台上的注册表设置 运行 Windows 的多个版本,Apple 上的 属性 list(PLIST)平台 运行 macOS 甚至浏览器级别开关。
但到目前为止 NONE 这些方法都适用于 SELENIUM
此对话框是在操作系统 (OS) 级别的浏览器(和 Selenium)之外生成的。 似乎 使用 Selenium 时,您必须在 OS 级别处理此对话框。
这些模块可能有助于在 OS 级别处理此对话框。
- win32gui - 微软
- win32com - 微软
- appscript - 苹果
我在 Github 的 SeleniumHQ/selenium 下发现了与您类似的问题。
问题 AddUserProfilePreference: Protocol_handler 已关闭且从未解决。
原版 POST -- 01/31/2021
我已经厌倦了绕过对话:
driver.switch_to.alert.accept()
但是这个调用抛出这个错误:
selenium.common.exceptions.NoAlertPresentException: Message: no such alert (Session info: MicrosoftEdge=88.0.705.56)
我尝试通过 EdgeOptions():
单独和分组传递这些选项
edge_options.add_argument("--disable-popup-blocking")
edge_options.add_argument('--disable-default-apps')
edge_options.add_argument('--allow-silent-push')
edge_options.add_argument('--disable-notifications')
edge_options.add_argument('--suppress-message-center-popups')
edge_options.add_argument('--inprivate')
但对话框仍然出现。
我也试过这个:
from msedge.selenium_tools import Edge
from msedge.selenium_tools import EdgeOptions
edge_driver = '/usr/local/bin/msedgedriver'
edge_options = EdgeOptions()
edge_options.use_chromium = True
prefs = {'profile.default_content_setting_values.notifications': 2}
edge_options.add_experimental_option('prefs', prefs)
edge_capabilities = edge_options.capabilities
# I needed this to work on macOS
edge_capabilities["platform"] = "ANY"
edge_capabilities.update(edge_options.to_capabilities())
driver = Edge(executable_path=edge_driver, capabilities=edge_capabilities)
driver.get("https://zoom.us/j/000-000-000")
但是再次弹出对话框。
我还尝试编辑默认的 Microsoft Edge 配置文件。在此编辑期间,我允许我的测试站点 (zoom.us) 执行大部分操作。
from msedge.selenium_tools import Edge
from msedge.selenium_tools import EdgeOptions
edge_driver = '/usr/local/bin/msedgedriver'
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument("user-data-dir=/Users/user_name/Library/Application Support/Microsoft Edge/User Data")
edge_capabilities = edge_options.capabilities
# I needed this to work on macOS
edge_capabilities["platform"] = "ANY"
edge_capabilities.update(edge_options.to_capabilities())
driver = Edge(executable_path=edge_driver, capabilities=edge_capabilities)
driver.get("https://zoom.us/j/000-000-000")
但是还是弹出了对话框,但是下载了zoom应用,以前是不会的。
我还使用 edge_options.add_argument('switch_name') 测试了其中的数十个 switches,但像以前一样没有任何效果。
所以就像我之前所说的那样,这个对话框不是一个普通的警报,它可能需要 Selenium 之外的代码或设置。我正在尝试确定需要采取哪些额外措施。
对我来说,您似乎需要找到一个 python 模块甚至 OS 应用程序来确定 PID 或该弹出窗口的焦点。一旦您可以通过 OS 确定您应该能够关闭对话框。
我无法测试这个 示例,它应该会停止每个站点的对话。
在此 Microsoft Forum discussion 中,用户正在讨论如何阻止这些警报在 Microsoft Edge 浏览器中发生。用户建议为 MacOS 启用 PLIST 或为 Microsoft OS.
启用注册表项
我测试了 PLIST,它可以在 Microsoft Edge 浏览器中运行,但仅当它不受 selenium.
控制时
更新 -- 02-04-2021
我也测试了这些开关,但没有解决对话框问题。
# references
#
# 1. https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc
#
# 2.
#
# 3. https://support.google.com/chrome/a/thread/62872506?hl=en
#
# 4. https://bugs.chromium.org/p/chromium/issues/detail?id=982341
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities().CHROME
prefs = {"protocol_handler": {"allowed_origin_protocol_pairs": {"https://zoom.us/*": {"zoom.us": True}}}}
# prefs = {"protocol_handler": {"excluded_schemes": {"zoom": False}}}
# prefs = {"protocol_handler": {"policy.auto_launch_protocols_from_origins": {"https://zoom.us/*": {"zoom.us": True}}}}
# prefs = {"AutoLaunchProtocolsFromOrigins": [{"allowed_origins": ["*"], "protocol":"zoom.us"}]}
chrome_options.add_experimental_option('prefs', prefs)
capabilities.update(chrome_options.to_capabilities())
旁注:
我能够使用以下开关禁用横幅“Microsoft Edge 正在由自动测试软件控制”:
edge_options.add_experimental_option("useAutomationExtension", False)
edge_options.add_experimental_option("excludeSwitches", ['enable-automation'])
----------------------------------------
My system information
----------------------------------------
Platform: macOS
Python: 3.8.0
msedge-selenium-tools: 3.141.2
----------------------------------------
当 运行 Selenium 上的一个进程时,我得到一个弹出窗口(这似乎是 Edge 浏览器的本机)。尝试以下操作时:
browser.switch_to.alert.accept()
、
我收到错误
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
我已经尝试等待一段时间让弹出窗口出现,并且尝试使用 Edge 选项无济于事。
我必须的另一个想法是模拟按下左箭头键然后在弹出窗口激活时输入,但是我需要 select selenium 上的特定元素并且找不到弹出窗口。
from msedge.selenium_tools import Edge, EdgeOptions
options = EdgeOptions()
options.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
browser = Edge(options=options)
也许这是另一种类型的警报?
options.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
您正在启用通知将其更改为 2 或完全删除它
此外,警报仅适用于通过 windows.alert()
抛出的警报看到的警报来自 chrome 或浏览器,而不是网站本身。所以你不能使用 switch 来提醒
不太确定,但也许浏览器不信任该程序并需要用户的许可 - 所以它不允许您使用该程序接受。
你的键模拟想法可能有效,使用键盘库,我很确定它是默认的,它可能不是,
并模拟您的按键,希望对您有所帮助。
我现在明白了为什么你最初在这个问题上提供了 50 点赏金,因为通过 Selenium 解决它是一个非常复杂的问题。
已解决 -- 2021 年 2 月 5 日
这应该不是这么难解决的!!我对多个论坛上关于此问题的所有帖子感到非常惊讶。解决这个问题需要很多线索和错误。
第 1 步:
打开 Microsoft Edge 并导航到调用对话框的站点,如下所示。
第 2 步:
选中复选框 - 允许在关联的应用程序中打开此类链接。单击“打开”。关闭关联的应用程序并关闭 Microsoft Edge。
第 3 步:
重新打开 Microsoft Edge 并导航至 edge://settings/content/applicationLinks
现在允许应用程序(例如,缩放)自动打开。
第 4 步:
关闭 Microsoft Edge 并使用以下代码启动 Selenium:
from msedge.selenium_tools import Edge
from msedge.selenium_tools import EdgeOptions
edge_driver = '/usr/local/bin/msedgedriver'
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument("user-data-dir=/Users/user_name/Library/Application Support/Microsoft Edge/User Data")
edge_options.add_argument("profile-directory=Profile 1")
edge_options.add_experimental_option("useAutomationExtension", False)
edge_options.add_experimental_option("excludeSwitches", ['enable-automation'])
# I needed this to work on macOS
edge_capabilities = edge_options.capabilities
edge_capabilities["platform"] = "ANY"
edge_capabilities.update(edge_options.to_capabilities())
driver = Edge(executable_path=edge_driver, options=edge_options)
driver.get("https://zoom.us/j/000-000-000")
缩放应用程序将在没有对话框的情况下自动打开。
似乎 msedge 或 selenium 每次启动时都会创建一个新的配置文件,这种情况仍然发生,但现在正在继承配置文件 1 的参数。
更新 -- 2021 年 2 月 4 日
根据大量研究,似乎 这个对话框 不能 在 Selenium 时处理正在控制 Google Chrome、Microsoft Edge 或 Mozilla Firefox。
可以使用多种方法在 Selenium 之外抑制该对话框,包括 Microsoft 平台上的注册表设置 运行 Windows 的多个版本,Apple 上的 属性 list(PLIST)平台 运行 macOS 甚至浏览器级别开关。
但到目前为止 NONE 这些方法都适用于 SELENIUM
此对话框是在操作系统 (OS) 级别的浏览器(和 Selenium)之外生成的。 似乎 使用 Selenium 时,您必须在 OS 级别处理此对话框。
这些模块可能有助于在 OS 级别处理此对话框。
- win32gui - 微软
- win32com - 微软
- appscript - 苹果
我在 Github 的 SeleniumHQ/selenium 下发现了与您类似的问题。 问题 AddUserProfilePreference: Protocol_handler 已关闭且从未解决。
原版 POST -- 01/31/2021
我已经厌倦了绕过对话:
driver.switch_to.alert.accept()
但是这个调用抛出这个错误:
selenium.common.exceptions.NoAlertPresentException: Message: no such alert (Session info: MicrosoftEdge=88.0.705.56)
我尝试通过 EdgeOptions():
单独和分组传递这些选项edge_options.add_argument("--disable-popup-blocking")
edge_options.add_argument('--disable-default-apps')
edge_options.add_argument('--allow-silent-push')
edge_options.add_argument('--disable-notifications')
edge_options.add_argument('--suppress-message-center-popups')
edge_options.add_argument('--inprivate')
但对话框仍然出现。
我也试过这个:
from msedge.selenium_tools import Edge
from msedge.selenium_tools import EdgeOptions
edge_driver = '/usr/local/bin/msedgedriver'
edge_options = EdgeOptions()
edge_options.use_chromium = True
prefs = {'profile.default_content_setting_values.notifications': 2}
edge_options.add_experimental_option('prefs', prefs)
edge_capabilities = edge_options.capabilities
# I needed this to work on macOS
edge_capabilities["platform"] = "ANY"
edge_capabilities.update(edge_options.to_capabilities())
driver = Edge(executable_path=edge_driver, capabilities=edge_capabilities)
driver.get("https://zoom.us/j/000-000-000")
但是再次弹出对话框。
我还尝试编辑默认的 Microsoft Edge 配置文件。在此编辑期间,我允许我的测试站点 (zoom.us) 执行大部分操作。
from msedge.selenium_tools import Edge
from msedge.selenium_tools import EdgeOptions
edge_driver = '/usr/local/bin/msedgedriver'
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument("user-data-dir=/Users/user_name/Library/Application Support/Microsoft Edge/User Data")
edge_capabilities = edge_options.capabilities
# I needed this to work on macOS
edge_capabilities["platform"] = "ANY"
edge_capabilities.update(edge_options.to_capabilities())
driver = Edge(executable_path=edge_driver, capabilities=edge_capabilities)
driver.get("https://zoom.us/j/000-000-000")
但是还是弹出了对话框,但是下载了zoom应用,以前是不会的。
我还使用 edge_options.add_argument('switch_name') 测试了其中的数十个 switches,但像以前一样没有任何效果。
所以就像我之前所说的那样,这个对话框不是一个普通的警报,它可能需要 Selenium 之外的代码或设置。我正在尝试确定需要采取哪些额外措施。
对我来说,您似乎需要找到一个 python 模块甚至 OS 应用程序来确定 PID 或该弹出窗口的焦点。一旦您可以通过 OS 确定您应该能够关闭对话框。
我无法测试这个
在此 Microsoft Forum discussion 中,用户正在讨论如何阻止这些警报在 Microsoft Edge 浏览器中发生。用户建议为 MacOS 启用 PLIST 或为 Microsoft OS.
启用注册表项我测试了 PLIST,它可以在 Microsoft Edge 浏览器中运行,但仅当它不受 selenium.
控制时更新 -- 02-04-2021
我也测试了这些开关,但没有解决对话框问题。
# references
#
# 1. https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc
#
# 2.
#
# 3. https://support.google.com/chrome/a/thread/62872506?hl=en
#
# 4. https://bugs.chromium.org/p/chromium/issues/detail?id=982341
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities().CHROME
prefs = {"protocol_handler": {"allowed_origin_protocol_pairs": {"https://zoom.us/*": {"zoom.us": True}}}}
# prefs = {"protocol_handler": {"excluded_schemes": {"zoom": False}}}
# prefs = {"protocol_handler": {"policy.auto_launch_protocols_from_origins": {"https://zoom.us/*": {"zoom.us": True}}}}
# prefs = {"AutoLaunchProtocolsFromOrigins": [{"allowed_origins": ["*"], "protocol":"zoom.us"}]}
chrome_options.add_experimental_option('prefs', prefs)
capabilities.update(chrome_options.to_capabilities())
旁注:
我能够使用以下开关禁用横幅“Microsoft Edge 正在由自动测试软件控制”:
edge_options.add_experimental_option("useAutomationExtension", False)
edge_options.add_experimental_option("excludeSwitches", ['enable-automation'])
----------------------------------------
My system information
----------------------------------------
Platform: macOS
Python: 3.8.0
msedge-selenium-tools: 3.141.2
----------------------------------------