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

Opera 87 - no operadriver? #100

Open
krb-vci opened this issue May 19, 2022 · 18 comments
Open

Opera 87 - no operadriver? #100

krb-vci opened this issue May 19, 2022 · 18 comments

Comments

@krb-vci
Copy link

krb-vci commented May 19, 2022

Is Opera no longer publishing new versions of operadriver? The latest here, updated 2 months ago, is for Opera 85. I test a health care website, and we can only support browsers that can be tested and documented. Without a working driver I am forced to stop supporting Opera, and to direct all the health care users to browsers I can test and document.
I'd like to be able to support Opera, especially for users in Europe, but need a standards-compliant webdriver.
Any chance of seeing one soon, or should my organization and I give up and start directing all users to Edge?

@rkrupski
Copy link
Collaborator

It looks like an issue with default sorting of release on GitHub as the latest one displayed is Opera 85 indeed, but as you can see on page 3 webdrivers for both Opera Stable 87 and Opera Stable 86 were uploaded.

Here is the link to "proper" latest release.

@farukborann
Copy link

@rkrupski
i get this error :
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Missing or invalid capabilities (Driver info: operadriver=99.0.4844.51 (d537ec02474b5afe23684e7963d538896c63ac77-refs/branch-heads/4844@{#875}),platform=Windows NT 10.0.19044 x86_64)
in this line :
driver = webdriver.Opera(executable_path='./files/operadriver.exe')
İ searhed in google but i cant fix it.
My opera stable 87 installed in default location and im using driver version 101 (last).
Can u help me ?

@krb-vci
Copy link
Author

krb-vci commented May 23, 2022

@rkrupski
Thank you. I have it working now.

I have another question to ask, and it may affect Omer Faruk Boran (above) also.

(I am wondering what version of Selenium Omer is using.) I have been unable to use the newest version – 4, with Opera. When I ask the people in the selenium chat, they tell me that the operadriver is not supported in selenium 4 because it is not compliant with W3 webdriver standards. It seems like Selenium 4 is more exacting than older selenium versions.
I run with Selenium 3.141.0 – which is most recent version before the release of 4.0.

Compatibility with Selenium is a really big thing for people like me who do automated testing of critical sites – I would love it if operadriver incompatibility issues could be fixed. Using an old version causes a number of problems that I need to compensate for with other browsers.

Thanks.

@rkrupski
Copy link
Collaborator

@krb-vci, that's true, in Selenium bindings OperaOptions is still using old naming which is invalid to the W3C. However, there is a workaround - please have a look at my past comment.

@omerboran63 try to use the above workaround (initialize ChromeOptions() and add options.add_experimental_option('w3c', True)). Also make sure the latest version of operadriver.exe is in the path:
Running operadriver -v should give you following output:
OperaDriver 101.0.4951.64 (d1daa9897e1bc1d507d6be8f2346e377e5505905-refs/branch-heads/4951@{#1208})

@krb-vci
Copy link
Author

krb-vci commented May 25, 2022

@rkrupski - I am completely confused. I am trying to initiate Opera in C#.
Based on your snippet I am guessing something like this:

   string operaExeLocation = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\AppData\Local\Programs\Opera\87.0.4390.25\opera.exe";
   var  options = new ChromeOptions();
   options.AddArgument("start-maximized");
   options.AddArgument("disable-infobars");
   options.AddArgument("wc3");
   options.BinaryLocation = operaExeLocation;
   driver = new ChromeDriver(driverDir, options);

Clearly this is a problem because I am pointing to the directory where I put the drivers, but I do not name the operadriver.exe. I have no idea how to do that and cannot find documentation on it.

Can you help me understand how to set the options and the driver?

@rkrupski
Copy link
Collaborator

@krb-vci w3c option is incorrectly used in your snippet above. It's not a cmd line switch for Opera binary (this is what AddArgument/add_argument method really does), but an additional option for Opera webdriver. In Python it is specified as:
options.add_experimental_option('w3c', True).

Regarding location of operadriver. In Python I can use something like this:
driver = webdriver.Opera(options=options, executable_path="C:\\webdriver\\operadriver.exe")

Sample code in Python to drive Opera from a given location using webdriver (+ selenium 4) from a specific folder would look as follow:

options = webdriver.ChromeOptions()
options.binary_location = "C:\\custom_install\\opera_stable\\opera.exe"
options.add_experimental_option('w3c', True)
driver = webdriver.Opera(options=options, executable_path="C:\\webdrivers\\operadriver.exe")
...

@krb-vci
Copy link
Author

krb-vci commented May 27, 2022

@rkrupski - I am still not succeeding. The C# implementation is clearly different from the Python implementation. The C# selenium library ( namespace OpenQA.Selenium.Chromw) does not have "add_experimental_option." One error message I got while trying different possibilities suggested using the options.UseSpecCompliantProtocol property - but that did not work either. I am hoping someone who knows the C# library reads this and responds. I'm still kind of a newbie, and struggling with lack of documentation details.

@WhoAmI-2022
Copy link

WhoAmI-2022 commented May 29, 2022

You can try:

var options = new OperaOptions();
service = OperaDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
options.AddArgument("user-data-dir=" + pathName);

driver = new OperaDriver(service, options);

@krb-vci
Copy link
Author

krb-vci commented May 29, 2022

@WhoAmI-2022 operadriver class is no longer supported in selenium 4. Only 3.141 and earlier.

@titusfortner
Copy link

The right way to use Opera in Selenium 4.2+ is to use ChromeOptions and pass in the location to the opera browser. Please do not include the w3c parameter.

See relevant language examples here:
https://www.selenium.dev/documentation/webdriver/getting_started/open_browser/#opera

The lack of updates to this project and not getting a response to issue #88 led us to choose to remove support for it. Chromedriver will successfully drive Opera in the required protocol.

@mialeska
Copy link

mialeska commented Aug 18, 2022

Found a solution unexpectedly by comparing java and dotnet implementation and documentation on selenium.dev.
Solution was to prepare proper ChromeOptions:

  1. set binary to location of launcher.exe

  2. set start arguments: "--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"

  3. ! force set "w3c" to true.
    In java this is quite simple: options.setExperimentalOption("w3c", true);
    In C# such capability is forbidden as already known, so I had to use the reflection to forcibly add it to additionalChromeOptions private dictionary in ChromiumOptions class:

             var field = typeof(ChromiumOptions).GetField("additionalChromeOptions", BindingFlags.NonPublic | BindingFlags.Instance);
             if (field.GetValue(options) is Dictionary<string, object> optionsDictionary)
             {
                 optionsDictionary["w3c"] = true;
                 field.SetValue(options, optionsDictionary);
             }
             options.BinaryLocation = BinaryLocation;
    
  4. You need to use operadriver executable, not the chromedriver. You can check out the latest operadriver here: https://github.com/operasoftware/operachromiumdriver/releases . And you need to tell the ChromeDriver that you're using it when instantiating.

    var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(driverDir, "operadriver.exe"), options);
    

Hope this would help you @krb-vci

I'm working now on integration of these actions into the Aquality.Selenium nuget package, you can check out our solution - we have cross-browser support with easy json configuration. Template project is located here: https://github.com/aquality-automation/aquality-selenium-dotnet-template

@krb-vci
Copy link
Author

krb-vci commented Aug 18, 2022 via email

@mialeska
Copy link

@krb-vci the thing I forgot to mention - it would not work with the chromedriver.exe. You need to use operadriver executable, not the chromedriver. You can check out the latest operadriver here: https://github.com/operasoftware/operachromiumdriver/releases . And you need to tell the ChromeDriver that you're using it when instantiating.
I prefer to use the WebDriverManager to download driver binaries "on the fly", but you can also specify the path to your local storage. Then your code will look like this:

string operaLauncherExeLocation = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\AppData\Local\Programs\Opera\launcher.exe";
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("disable-infobars");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
options.BinaryLocation = operaLauncherExeLocation;
string driverDir = AppDomain.CurrentDomain.BaseDirectory + "Drivers";
var field = typeof(ChromiumOptions).GetField("additionalChromeOptions", BindingFlags.NonPublic | BindingFlags.Instance);
if (field.GetValue(options) is Dictionary<string, object> optionsDictionary)
{
     optionsDictionary["w3c"] = true;
     field.SetValue(options, optionsDictionary);
}
var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(driverDir, "operadriver.exe"), options);

And if you decide to use the WebDriverManager:

string operaLauncherExeLocation = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\AppData\Local\Programs\Opera\launcher.exe";
var config = new OperaConfig();
var driverPath = new DriverManager().SetUpDriver(config, "Latest");    
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("disable-infobars");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
options.BinaryLocation = operaLauncherExeLocation;
var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), config.GetBinaryName()), options);

@krb-vci
Copy link
Author

krb-vci commented Aug 19, 2022

Fantastic! Thank you!

@krb-vci
Copy link
Author

krb-vci commented Aug 22, 2022

@mialeska -
Before starting a new issue i wanted to reach out to you about a new problem I found.
In some of my tests I need to open 2 instances of the browser. For example - I test some features with limited credentials, but in the middle of the test I need to log in with high level credentials and make some changes that can't be done in the other instance.
With the older version of Selenium I was able to simply open 2 drivers (driver 1 and driver 2), and they both just worked. Now, using the code you taught me, I get errors with the second browser.
I also notice that I get a command line window for each instance, and they share the same name (and I wonder if they are conflicting at the thread level).
Presuming you may be able to look at this, would you like me to keep adding info here, or to start a new issue?

@mialeska
Copy link

mialeska commented Aug 23, 2022

I'm not sure what might cause this issue - maybe you're sharing the same remote debugging port(the one added as argument, 9222).

@krb-vci
Copy link
Author

krb-vci commented Aug 24, 2022

Thanks for your note. I fixed the problem by using port 1212 for the remote debugging port for the second driver instance. I have not yet tried WebDriverManager - but will. I have been making a lot of changes in the project and will try it soon.

@krb-vci
Copy link
Author

krb-vci commented Oct 11, 2022 via email

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

No branches or pull requests

6 participants