selenium如何关闭chrome弹出窗口

2024-05-14 15:11:27 发布

您现在位置:Python中文网/ 问答频道 /正文

scrshot 我尝试了我能找到的任何东西,但我无法让selenium解除此警报。我不认为这是一个警告了,虽然,因为我没有得到任何AlertPresentException当我尝试

driver.switch_to.alert.dismiss()

有什么想法吗

以下是HTML页面的相关部分:

<iframe id="teamsLauncher" src="msteams:/l/team/19:95f3ef22a37040fca83b679b64f96da1@thread.tacv2/conversations?groupId=09988212-e3a1-4187-b067-a805e512e0a4&amp;tenantId=d348f9ab-4879-4a60-ab50-5c420b11470c&amp;deeplinkId=2deee564-c6b3-4d5d-b097-93900dd14620&amp;launchAgent=join_launcher&amp;type=team&amp;directDl=true&amp;msLaunch=true&amp;enableMobilePage=true&amp;fqdn=teams.microsoft.com" style="display: none;"></iframe>
<script>var modernBrowser="fetch"in window&&"assign"in Object&&"Set"in window,bundles=[],polyfills="";function injectScript(n,e,s){var t=document.createElement("script");t.src=n,t.async=e,t.onload=s,document.body.appendChild(t)}function loadBundles(n){for(key in bundles)injectScript(bundles[key],n)}function loadPolyfills(){polyfills&&injectScript(polyfills,!1,function(){loadBundles(!1)})}bundles.push("https://statics.teams.microsoft.com/hashedjs-launcher/launcher.5c24f1e70f34f56835c7.js"),polyfills="https://statics.teams.microsoft.com/hashedjs-launcher/polyfills.1e46ca6473519cf1be5d.js",modernBrowser?loadBundles(!0):loadPolyfills(),window.addEventListener("load",function(){injectScript("https://az725175.vo.msecnd.net/scripts/jsll-4.js",!0,function(){var n={coreData:{appId:"JS:teams.microsoft.com",market:window.navigator.language||"en-US"}};awa&&awa.init&&awa.init(n)})})</script>

还尝试了actionchains,但发送escape密钥没有任何作用


Tags: incomtruevarscriptfunctionwindowmicrosoft
2条回答

考虑使用库PyAutoGUI,它允许Python控制鼠标和键盘。如果每次都将窗口保持在同一位置,则可以使用鼠标单击功能的静态x y坐标来接受弹出窗口并允许您继续

不运行代码很难说,但也许可以尝试使用chrome选项禁用chrome弹出窗口

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(" disable-notifications")
driver = webdriver.Chrome(options=chrome_options)

我希望这能奏效

相关问题 更多 >

    热门问题