MickM
MickM

Reputation: 21

Python Selenium - Common Script for Chrome, Firefox & IE

We are currently investigating Selenium as a test tool for web servers embedded in a range of controllers. I was hoping to reuse the same Python (2.7) code for all drivers but although Chrome and Firefox play nicely, IE11 (surprise?) doesn't like it. IE opens but then Python throws an exception.

At first I thought the issue was just with the user:pwd included in the URL...

driver.get("http://" + "acc:[email protected]")

But even after removing the login info and manually entering the login, the subsequent code...

(driver.switch_to.frame("links_frame") 

then also fails.

Is there some disparity between the drivers that would cause this? I've read of others successfully reusing the same code for all browsers so have to figure that I may be doing something wrong?

Details:

In the first instance...

...line 25, in driver.get("http://" + "acc:[email protected]")
...\webdriver.py", line 185, in get self.execute(Command.GET, {'url': url})
...webdriver.py", line 173, in execute self.error_handler.check_response(response) ...\errorhandler.py", line 164, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: u'Failed to navigate to acc:[email protected]. This usually means that a call to the COM method IWebBrowser2::Navigate2() failed.'

In the second instance:
...line 33, in driver.switch_to.frame("links_frame") # selects the iframe containing the next element for test ...\webdriver\remote\switch_to.py", line 64, in frame self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference})
...\webdriver.py", line 173, in execute self.error_handler.check_response(response)
...\webdriver\remote\errorhandler.py", line 164, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.UnexpectedAlertPresentException: Message: u'Modal dialog present' – –

Upvotes: 1

Views: 915

Answers (3)

Seleniumuser
Seleniumuser

Reputation: 11

You are correct. Modern versions of IE don't allow you to pass Basic Authentication credentials in the URL. Most other browsers still allow it.

Upvotes: 1

Corey Goldberg
Corey Goldberg

Reputation: 60604

to answer the first part of your question...

At first I thought the issue was just with the user:pwd included in the URL

You are correct. Modern versions of IE don't allow you to pass Basic Authentication credentials in the URL. Most other browsers still allow it.

For an explanation, see Microsoft's knowledge base article: 834489

(Note: There are hacks to disable this behavior. There are also better ways to handle authentication)

Upvotes: 1

mutt
mutt

Reputation: 793

IE is annoying...but it shouldn't be python that is the problem. Be sure to set all of your Protected mode settings to the same for all zones (enabled/disabled). Otherwise IEDriver will lose the window after it opens which seems similar to what you are experiencing.

You can absolutely use the same code for all tests...the driver portion changes, but they are all based on the same base class/interfaces. For python...importing the same libraries.

Here are some IE references: Selenium WebDriver on IE11

Upvotes: 1

Related Questions