Closed lkende closed 12 years ago
Would still like some clarifications, but I did get it working finally. Not sure why it didn't work the first time, but the capabilities object works like this:
DesiredCapabilities capabilities = DesiredCapabilities.opera(); capabilities.setCapability("opera.binary",pathToOpera);
I would suggest changing the reference from opera.path to opera.binary in the github documenation, and I suggest updating selenium wiki if OperaDriverSettings class no longer exists.
Thanks.
The OperaDriver wiki page in the Selenium project on Google Code was fairly old, and I've now updated this. The most recent information about OperaDriver is always available in its README: https://github.com/operasoftware/operadriver/blob/master/README.md
When it comes to the Opera binary path confusion, I'd really recommend using the capabilities. You can specify which Opera to use like this:
DesiredCapabilities c = DesiredCapabilities.opera();
c.setCapability("opera.binary", "/path/to/opera");
WebDriver driver = new OperaDriver(c);
The README is not great, and I'll make it a task to rewrite that when releasing the next version.
UPDATE: Adding this for myself and others reference. There are two things to note that took me a couple of hours to figure out concerning the setting of the path:
1: OPERA_PATH will be used regardless of whether the opera.binary is set in the capabilities object. I think this is wrong personally and would suggest the precedence follow this order:
-check and use opera.binary in DesiredCapabilities if set (this is set at run-time so would make sense that it would override any others) -else check and use OPERA_PATH variable if exists -else check and use default location for the OS -else fail if none of those are successful.
2: You cannot have spaces in the file path. I was using c:\Program File (x86)\Opera\opera.exe in my environment variable, which is in fact the default install location on Window 7 64-bit. I finally had to use the short name to get it working: C:\PROGRA~2\Opera\opera.exe.
As of latest HEAD, with the introduction of OperaSettings, OPERA_PATH does no longer override opera.binary from capabilities.
When it comes to specifying the path to a Windows executable, you need to either use a Java compatible file path (forward slashes or double escape your backward slashes) or a compatible URI.
these methods are deprecated now let me know if there is new method for this
What do you mean @UnicodeSystem, could you be specific about what is deperecated, what you're trying to do and what isn't working?
I was using this DesiredCapabilities c = DesiredCapabilities.opera(); c.setCapability("opera.binary", "/path/to/opera"); WebDriver driver = new OperaDriver(c);
on this line i am getting warning that this method has been deprecated DesiredCapabilities c = DesiredCapabilities.opera();
Hi, that is actually the Selenium project which is doing. Reading the code, I see that they have removed presto support in their newest versions. However, before they did that, they only deprecated using "opera" for a while, what they want you to use is "operaPresto" instead for presto, and "operaBlink" for new-Opera.
So try DesiredCapabilities.operaPresto()
. Even if Selenium project does not support Opera Presto, it (the technology) will continue to work.
For whoever coming here with JavaScript target, here is the code:
browserDriver = require("selenium-webdriver/opera");
options = new browserDriver.Options();
options.setOperaBinaryPath("Path to Opera.exe");
var opera = new webDriver.Builder()
.withCapabilities(options.toCapabilities())
.build();
Though there's several comments in the documentation about setting the path to the binary, they are confusing, and inconsistent with documentation on Selenium WebDriver wiki. Also, I can't get them to work since upgrading to newer selenium 2.20.
With an earlier version of selenium 2.11, I was able to use the OperaDriverSettings object like is shown in the selenium wiki: http://code.google.com/p/selenium/wiki/OperaDriver#Settings
OperaDriverSettings settings = new OperaDriverSettings(); settings.setOperaBinaryLocation("/path/to/opera"); WebDriver driver = new OperaDriver(settings);
Since around selenium 2.15, the OperaDriverSettings object doesn't exist, or if it does, the path has changed as this import statement fails: import com.opera.core.systems.settings.OperaDriverSettings;
Trying to fix this from the current documentation on github for OperaDriver, using the capabilities object or setting the system property should work, but cannot get Opera to launch when specifying the path this way. Here's the methods I've tried:
pathToOpera = "c:\Program Files\Opera 10.10 Beta\opera.exe"; //just happens to be where it is and not in a position to change it
//trying with capabilities DesiredCapabilities capabilities = DesiredCapabilities.opera(); capabilities.setCapability("opera.binary",pathToOpera); driver = new OperaDriver(capabilities);
//trying various set property methods System.setProperty("opera.binary",pathToOpera); System.setProperty("opera.path",pathToOpera); //at another point in the docs, it says to set "opera.path" System.setProperty("webdriver.opera.binary");//notice added "webdriver" prefix since most other drivers look for this. System.setProperty("opera.binary","c:\opera-wrapper-script.txt"); //tried using wrapper script driver = new OperaDriver();
Setting OPERA_PATH as an environment variable is not an option for me.
So, with the capabilities object or setProperty method, should I be setting opera.binary or opera.path or webdriver.opera.binary, or what? Or maybe there's something else I am missing?