Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set unhandledPromptBehavior capability using local browser #1825

Closed
bt-ctsmith opened this issue Mar 28, 2023 · 7 comments
Closed

set unhandledPromptBehavior capability using local browser #1825

bt-ctsmith opened this issue Mar 28, 2023 · 7 comments
Labels
question Someone is looking for answers

Comments

@bt-ctsmith
Copy link

I have the need to set the unhandledPromptBehavior capability to ignored when using a local browser instance. This appears to have been a change in how the weddrivers handle this specific capability in the past year, but I am not sure when. Before, I was able to do the below, and the alert would stay open between the click (which, in my case, presents a confirm alert) and self.wait_for_and_accept_alert(). See snippet below:

        self.update_text('#field', 'text')
        self.click('#save_button')
        self.wait_for_and_accept_alert()

I have tried using the --cap_file option, but looking at browser_launcher.py that only applies to remote instances, not local. I was able to force it by adding the capability in _set_chrome_options and _set_firefox_options.

seleniumbase: 4.13.18
selenium: 4.8.2

Fedora Linux 37
chromedriver: 111.0.5563.64
Chrome: 111.0.5563.146
geckodriver: 0.32.2
Firefox: 111.0.1 (602aa16c20d4 2023-02-08 00:09 +0000)

@mdmintz
Copy link
Member

mdmintz commented Mar 28, 2023

Welcome! self.click(SELECTOR) actions are followed by a self.wait_for_ready_state_complete() to make sure that any actions or page loads caused by the click are done processing. This makes a call to self.execute_script(...), but it turns out that this causes pop-ups to immediately go away. To compensate, use self.find_element(SELECTOR).click() instead of self.click(SELECTOR) for these specific clicks. Then you can be sure that the pop-up will be there in the next step so that you can call self.wait_for_and_accept_alert() safely (or any other method that depends on the pop-ups being present).

I talked a bit about that in this earlier ticket: #600 (comment)

@mdmintz mdmintz added the question Someone is looking for answers label Mar 28, 2023
@bt-ctsmith
Copy link
Author

Thank you for the work around, that did allow me to interact with the alert.

@mdmintz mdmintz closed this as completed Mar 30, 2023
@Id1n
Copy link

Id1n commented Nov 11, 2023

hi
This method is great self.wait_for_ready_state_complete() , but it has one issue. When the alert has two or more buttons, it always selects Cancel. Is there any way to choose which button to select?

@mdmintz
Copy link
Member

mdmintz commented Nov 12, 2023

@Id1n Use self.accept_alert() for that.

@Id1n
Copy link

Id1n commented Nov 12, 2023

I have tried both methods self.wait_for_and_accept_alert() and self.accept_alert(). They are not efficient when it's unclear whether an alert is present or not because they have unlimited wait times, and if an alert doesn't occur, it can disrupt the program. Method self.wait_for_ready_state_complete(), however, continues the process if the alert doesn't appear. The only issue is that it lacks the capability to change the button.

@Id1n
Copy link

Id1n commented Nov 12, 2023

I've tested almost all scenarios, but this alert won't dismiss, and it throws this error.

An error occurred: Alert Text: Are you sure you want to submit?
Message: unexpected alert open: {Alert text : Are you sure you want to submit?}
(Session info: chrome=114.0.5735.134)
Stacktrace:
Backtrace:
GetHandleVerifier [0x0088A813+48355]
(No symbol) [0x0081C4B1]
(No symbol) [0x00725358]
(No symbol) [0x0077CDAD]
(No symbol) [0x0076A536]
(No symbol) [0x007482DC]
(No symbol) [0x007493DD]
GetHandleVerifier [0x00AEAABD+2539405]
GetHandleVerifier [0x00B2A78F+2800735]
GetHandleVerifier [0x00B2456C+2775612]
GetHandleVerifier [0x009151E0+616112]
(No symbol) [0x00825F8C]
(No symbol) [0x00822328]
(No symbol) [0x0082240B]
(No symbol) [0x00814FF7]
BaseThreadInitThunk [0x75907BA9+25]
RtlInitializeExceptionChain [0x7755BD3B+107]
RtlClearBits [0x7755BCBF+191]
Screenshot 2023-11-12 145754

Do you think there's a way to handle it?

@mdmintz
Copy link
Member

mdmintz commented Nov 12, 2023

@Id1n Do a regular element.click() or default_get(url) action to get to that pop-up, then do accept_alert().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers
Projects
None yet
Development

No branches or pull requests

3 participants