Alert box, Pop Up - Selenium Automation with Python, Pycharm IDE

Опубликовано: 13 Октябрь 2024
на канале: Trikam Patel
105
0

Alert box Pop Up - Selenium Automation with Python, Pycharm IDE
Click See More for the code:
Code Starts Here - - - - - - - - - - - - - - - - - - - - *- - - - - - - - - - - - - - - -

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome(executable_path="C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe")
driver.get("file:///G:/trikam/Alert.html")

driver.find_element_by_xpath("/html/body/div[2]/div/button").click()

time.sleep(5)

#driver.switch_to_alert().accept() # closes alert window using ok button

driver.switch_to_alert().dismiss() # closes alert by using cancel button