operasoftware / operachromiumdriver

OperaDriver for Chromium-based Opera releases
Other
261 stars 47 forks source link

How to solve this error (Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Opera binary) ? #56

Open ripalchauhan opened 6 years ago

ripalchauhan commented 6 years ago

Attempting to lunch Opera in windows 10 Using Selenium Web driver. Opera browser version 54, OperaDriver=2.36 or also tried latest one 2.37 but same exception coming.

import org.openqa.selenium.opera.OperaDriver;

public class OperaBrowser {

public static void main(String[] args) {

    String path =System.getProperty("user.dir");
    System.out.println("Where am I?" +path);

    System.setProperty("webdriver.opera.driver", path+"/drivers/operadriver.exe");
    OperaDriver driver = new OperaDriver();
    driver.get("https://www.google.co.in");
    String title = driver.getTitle();
    System.out.println(title);
    String URL = driver.getCurrentUrl();
    System.out.println(URL);
//  driver.close();
}

}

dmssargent commented 6 years ago

You have to specify the Opera binary path via OperaOptions . See https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/opera/OperaOptions.html#setBinary-java.lang.String- for more details.

If you are running on Windows, keep in mind #44 is still an issue, but the solution of directly passing the real Opera binary tends to work, see the comment by @wladzynski.

doubleShot666 commented 6 years ago

This worked for me. You have to specify the path of your opera binary file and add it in the options when you instanciate your WebDirver opbejct. See the code bellow.

.
.
.
static WebDriver webDriver;

@BeforeClass
    public static void setUpBeforeClass() throws Exception {
        String path = "E:\\operadriver_win64\\operadriver_win64\\operadriver.exe";
        OperaOptions options = new OperaOptions();
        options.setBinary("C:\\Program Files\\Opera\\56.0.3051.43\\opera.exe");
        System.setProperty("webdriver.opera.driver",path);
        webDriver = new OperaDriver(options);
    }
.
.
.
SaiNiranjan commented 5 years ago

@doubleShot666 I followed your code, I am getting below error,

org.openqa.selenium.SessionNotCreatedException: session not created: No matching capabilities found Build info: version: '3.141.59', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '12.0.2' Driver info: driver.version: OperaDriver

DorotaBFTester commented 4 years ago

doubleShot666 Thank you I tried to get it to work for 2 days, and your code worked!