This article describes how to handle page to Alert popups by Selenium method, create an alert pop with js.
driver.switch_to.alert.accept()
Script code is as follows:
import time from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() driver.implicitly_wait ( 6 ) # Implicit wait driver.get("https://www.baidu.com") time.sleep(1) driver.execute_script ( " window.alert ( 'test pop'); " ) time.sleep(2) driver.switch_to.alert.accept () # Click on the OK button to pop up inside the # driver.switch_to_alert (). Dismiss () # Click the X button pops up above