Reputation: 36453
tl/dr: What am I doing wrong?
I'm trying to run selenium tests locally and be compatible with Browserstack platform. I use this code to connect locally:
wd = webdriver.Remote('http://[email protected]:80/wd/hub', {'browser':'firefox'})
wd.get('http://google.com')
wd.get_screenshot_as_file('/tmp/googl.png')
wd.close()
I see a good screenshot in /tmp/
.
Now I try to do the same with local Selenium:
$ java -jar /usr/share/java/selenium-server-standalone-2.44.0.jar &
The server starts nominally. I try creating a session with Firefox (30.0), it works correctly. (Default browser is Opera.)
Then I try to run Python code:
wd = webdriver.Remote('http://localhost:4444/wd/hub', {'browser':'firefox'})
wd.get('http://google.com')
wd.get_screenshot_as_file('/tmp/googl2.png')
wd.close()
Selenium opens Opera instead of Firefox.
I see this in Python console:
Message: <html>
<head>
<title>Error 500 org/json/JSONObject</title>
</head>
<body>
<h2>HTTP ERROR: 500</h2><pre>org/json/JSONObject</pre>
<p>RequestURI=/wd/hub/session</p>
<p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>
Why does it open Opera instead of Firefox?
Upvotes: 3
Views: 633
Reputation: 163
Another solution (very close to the accepted answer) is to use predefined DesiredCapabilities constants:
from selenium import webdriver
capabilities = webdriver.DesiredCapabilities.FIREFOX.copy()
wd = webdriver.Remote('http://localhost:4444/wd/hub', desired_capabilities=capabilities)
In this case capabilities
is a dict already containing browserName
property set to firefox
.
Upvotes: 0
Reputation: 23827
The problem is in this line:
wd = webdriver.Remote('http://localhost:4444/wd/hub', {'browser':'firefox'})
Changing browser
to browserName
will fix it. Use
wd = webdriver.Remote('http://localhost:4444/wd/hub', {'browserName':'firefox'})
instead.
Upvotes: 3