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

No possibility for sending text on alert prompt #548

Closed
createNull opened this issue Apr 22, 2020 · 6 comments
Closed

No possibility for sending text on alert prompt #548

createNull opened this issue Apr 22, 2020 · 6 comments
Labels
external Outside SeleniumBase's scope. / Ask somewhere else.

Comments

@createNull
Copy link

Hi,

I am trying to send some text to an alert prompt, but can't figure out how using seleniumbase.

from seleniumbase import BaseCase
import time


class MyTestClass(BaseCase):

    def test_alerts(self):
        self.open("about:blank")
        self.execute_script('window.prompt("sometext","defaultText");')
        time.sleep(1.2)  # Not needed (Lets you see the alert pop up)
        self.wait_for_and_switch_to_alert(timeout=2)
        self.send_keys('*', 'newText')
        time.sleep(1.5)
        self.wait_for_and_accept_alert()
        time.sleep(0.8)  # Not needed (Lets you see the alert go away)

This version actually fails. Remove line 14 and it will pass, but it doesn't send any text regardless.

Session data
metadata: {'Python': '3.8.2', 'Platform': 'macOS-10.15.4-x86_64-i386-64bit', 'Packages': {'pytest': '5.3.5', 'py': '1.8.1', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.0.1', 'rerunfailures': '9.0', 'xdist': '1.31.0', 'ordering': '0.6', 'seleniumbase': '1.37.8', 'forked': '1.1.3', 'metadata': '1.8.0', 'cov': '2.8.1'}}

P.S. Just installed latest version of pytest and got this:
ERROR: seleniumbase 1.37.8 has requirement pytest==5.3.5; python_version >= "3.5", but you'll have pytest 5.4.1 which is incompatible.

@mdmintz
Copy link
Member

mdmintz commented Apr 22, 2020

@createNull I tried playing around with regular WebDriver calls to send text, but it didn't seem to work. It might be an issue on WebDriver's end and you might have to open an issue on the Selenium Project's GitHub page. As for the test, I've expanded on it, although still can't send text to the input.

from seleniumbase import BaseCase

class MyTestClass(BaseCase):

    def test_alerts(self):
        self.open("about:blank")
        self.execute_script('window.alert("ALERT!!!")')
        self.sleep(1.2)  # Not needed (Lets you see the alert pop up)
        self.wait_for_and_accept_alert()
        self.sleep(0.8)  # Not needed (Lets you see the alert go away)
        self.execute_script('window.prompt("My Prompt","defaultText");')
        self.sleep(1.2)  # Not needed (Lets you see the alert pop up)
        alert = self.wait_for_and_switch_to_alert(timeout=2)
        self.assert_equal(alert.text, "My Prompt")  # Not the input field
        self.wait_for_and_dismiss_alert()
        self.sleep(0.8)  # Not needed (Lets you see the alert go away)

If you can figure out a way to send text to an alert using regular WebDriver calls, I'm happy to add that into SeleniumBase as a standalone call.

As for the pytest requirements issue, there is a major regression in the latest version of pytest, so I pinned the dependency within SeleniumBase to a slightly older version that works perfectly. There's already a ticket on that here: #534
It might be some time before pytest resolves their issues in their latest version, given that the heads of their team all quit on the same day in a heated Twitter thread. https://twitter.com/brettsky/status/1248733160591908864?s=20
If you're using SeleniumBase, let SeleniumBase pick the version of pytest to use.

@mdmintz mdmintz added the external Outside SeleniumBase's scope. / Ask somewhere else. label Apr 23, 2020
@createNull
Copy link
Author

The issue here

@createNull
Copy link
Author

I managed to use Basic auth with python requests, but can't link it to selenium webdriver session.
Is there any workaround for it?

@mdmintz
Copy link
Member

mdmintz commented Apr 23, 2020

@createNull Looks like you found the original WebDriver issue. As for workaround, I found a StackOverflow post that may help you: https://stackoverflow.com/q/27322871

If you're connecting to a proxy server with authentication through Chromium, there's already a SeleniumBase solution built-in. Add the following to your run command:

--proxy=USER:PASS@HOST:PORT

@createNull
Copy link
Author

createNull commented Apr 24, 2020

Found this solution as well, but when it failed to log me in while copy pasting the URL inside the browser window (for Chrome), I gave up on it.
When using

self.open(USER:PASS@DOMAIN)

it works absolutely fine without using any --proxy in the command line.

Thank you for the assistance @mdmintz . Now I need to figure out where to store the credentials

@mdmintz
Copy link
Member

mdmintz commented Apr 24, 2020

@createNull Great! If you're all set, we can close this issue.

@mdmintz mdmintz closed this as completed Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Outside SeleniumBase's scope. / Ask somewhere else.
Projects
None yet
Development

No branches or pull requests

2 participants