Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

self.click with alert seems to have issues #1182

Answered by mdmintz
maburrub asked this question in Q&A
Discussion options

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()

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
0 replies
Answer selected by mdmintz
Comment options

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)

You must be logged in to vote
1 reply
Comment options

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.

Comment options

thanks

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /