Context:
- My script launch to a website using selenium webdriver
- The user fills in some stuff on the website
- The user will click a button which will popup a
confirm()
dialog box asking the user "Do you want to submit the data"
My intention:
My script would wait till the user click the button. Once it detects that the user clicked the button, my script would get a value of an element and then (somehow) click OK on the dialog box.
Question:
How do wait for the user to click the button?
How do I then click OK on the dialog box?
Additional Notes:
Using: chromedriver, Python 2.7
The button: <input id="submitID" type="button" class="medium" value="Submit filled Data">
[EDIT] Some code snippet:
The dialog popup is javascript popup:
if (window.confirm("Are you sure you want to submit the data?")) {
this.SaveData();
}
My code (simplified & modified for this question):
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
PATH_TO_CHROMEDRIVER = 'path/to/chromedriver'
URL = 'https://website-asking-user-to-fill-in-stuff.com'
driver = webdriver.Chrome(PATH_TO_CHROMEDRIVER)
driver.get(URL)
while True:
# loop until user close the chrome.
# If anyone has any better idea to
# WAIT TILL USER CLOSE THE WEBDRIVER, PLEASE SHARE IT HERE
try:
# --- main part of the code ---
waitForUserToClickButton() # this is what I need help with
driver.find_element_by_id('elementID').text
confirmJavascriptPopup() # this is also what I need help with
except WebDriverException:
print 'User closed the browser'
exit()