Reputation: 87
i use python and i want click "ok" button in Chrome selenium.
how can i click "ok" in selenium?
Upvotes: 2
Views: 1195
Reputation: 2288
Updated answer with testing on PC
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("http://testautomationpractice.blogspot.com/")
driver.find_element(By.XPATH, "//*[@id='HTML9']/div[1]/button").click()
sleep(5)
driver.switch_to.alert.dismiss() # or .accept()
Upvotes: 1
Reputation: 81
The .alert.accept() some others are mentioning should work, but from my experience it didnt work on the applications I ran.
These two ways worked for me:
links: subprocess: https://docs.python.org/3/library/subprocess.html xdotool: https://manpages.ubuntu.com/manpages/trusty/man1/xdotool.1.html
Upvotes: 1
Reputation: 33361
Accepting alert with Selenium in Python can be done with this:
driver.switch_to.alert.accept()
Upvotes: 2