简体   繁体   中英

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 ). I tried using sendkeys and using actions class aswell. 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. 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); // define action class actions.sendKeys(Keys.ESCAPE).build().perform(); // Press ESC key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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