-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
This does not work, the alert gets dismissed unexpectedly
self.click(alert_locator)
self.wait_for_and_accept_alert()
However this works fine. The alert shows fine and then accepted.
self.get_element(alert_locator).click()
self.wait_for_and_accept_alert()
Beta Was this translation helpful? Give feedback.
All reactions
That's expected behavior based on how Webdriver works. Calling any type of script while an alert is open will dismiss the alert, and a script is used to verify that the document.readyState
of the page is complete
after various actions such as clicking. More details on that here: #600
There are also many who consider that a feature because sometimes they want alerts to get dismissed automatically. For your situation, use self.get_element(alert_locator).click()
as needed to make sure the alert stays up if you need it to stay up.
Replies: 3 comments 1 reply
-
That's expected behavior based on how Webdriver works. Calling any type of script while an alert is open will dismiss the alert, and a script is used to verify that the document.readyState
of the page is complete
after various actions such as clicking. More details on that here: #600
There are also many who consider that a feature because sometimes they want alerts to get dismissed automatically. For your situation, use self.get_element(alert_locator).click()
as needed to make sure the alert stays up if you need it to stay up.
Beta Was this translation helpful? Give feedback.
All reactions
-
alert_locator locates a button on the page and when clicked the alert is shown. It is not a locator for an object within the alert window. what I am asking about is this: when calling self.click(alert_locator) to display the alert why does it get dismissed right before accepting it? why is not kept ? I just do not get what is the different between self.get_element(alert_locator).click() and self.click(alert_locator)
Beta Was this translation helpful? Give feedback.
All reactions
-
There's a big difference between self.get_element(alert_locator).click()
and self.click(alert_locator)
. The first isn't very reliable if the element is not clickable, but the second one will wait for the element to be fully clickable before clicking it. Also the error output is much nicer with the second one, which uses SeleniumBase smart-waiting. For most cases, you should probably use self.click(alert_locator)
, but if need an alert to remain up, use self.get_element(alert_locator).click()
instead.
Beta Was this translation helpful? Give feedback.
All reactions
-
thanks
Beta Was this translation helpful? Give feedback.