简体   繁体   English

使用 Selenium Webdriver 关闭警报

[英]Closing an Alert with Selenium Webdriver

Unable to close an alert which pop-ups once the url is navigated and enter something in the page( https://www.roadrunnersports.com ).无法关闭在导航 url 并在页面中输入内容后弹出的警报 ( https://www.roadrunnersports.com )。 I tried using sendkeys and using actions class aswell.我尝试使用 sendkeys 并使用操作 class。 Manually, I am able to close the alert but I want to automate that aswell.手动,我可以关闭警报,但我也想自动关闭警报。

Anyone suggest me a way to handle this?有人建议我处理这个问题的方法吗?

Note:Its not a sweet alert also to as I am unable to inspect the element.注意:这也不是一个甜蜜的警报,因为我无法检查该元素。

It looks like it isn't consistently the same modal. 看起来并不一致。 But, the ones I've seen can be cleared by hitting the Esc key. 但是,我看到的内容可以通过按Esc键清除。 Try using that with actions 尝试将其与动作配合使用

from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
actions = ActionChains(driver)
actions.send_keys(Keys.ESCAPE).perform()

Make sure you wait for the modal to appear though, it seems like it takes a bit. 确保您等待模态出现,不过这似乎需要一些时间。

Actions actions = new Actions(driver);动作 actions = new Actions(driver); // define action class actions.sendKeys(Keys.ESCAPE).build().perform(); // 定义动作 class actions.sendKeys(Keys.ESCAPE).build().perform(); // Press ESC key // 按退出键

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM