Problem with running Opera browser using Selenium through webdrivermanager

1.9k views Asked by At

I've got a problem with Opera browser using Selenium. To download browser binaries I'm using webdrivermanager plugin(https://github.com/bonigarcia/webdrivermanager)

This is a enum to implement different types of browsers:

public enum DriverType implements DriverSetup {

    CHROME {
        public WebDriver getWebDriverObject() {
            WebDriverManager.chromedriver().setup();
            return new ChromeDriver();
        }
    },
    FIREFOX {
        public WebDriver getWebDriverObject() {
            WebDriverManager.firefoxdriver().setup();
            return new FirefoxDriver();
        }
    },
    OPERA {
        public WebDriver getWebDriverObject() {
            WebDriverManager.operadriver().setup();
            return new OperaDriver();
        }
    }
}

There is a call of getWebDriverObject method:

public class DriverBase {

    public WebDriver driver;

    public WebDriver initializeBrowser() {
        DriverType driverType = DriverType.CHROME;

        try {
            String browser = System.getProperty("browser").toUpperCase();
            driver = DriverType.valueOf(browser).getWebDriverObject();
        } catch (Exception e) {
            System.out.println("No driver specified/Wrong driver specified, default tests running on Chrome");
            driver = driverType.getWebDriverObject();
        }
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        return driver;
    }
}

Before I run a tests I'm setting system property browser to "opera". And this is an output. Tests are running in chrome by default and opera browser didn't open so it doesn't work. How can I fix it?

    ProjectName > Login STANDARD_ERROR
    1160 [Test worker] WARN io.github.bonigarcia.wdm.WebDriverManager - The driver version for Opera No Instance(s) Available. is unknown .
.. trying with latest
    1163 [Test worker] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/operasoftware/operachromiumdri
ver/releases to seek operadriver
    1465 [Test worker] INFO io.github.bonigarcia.wdm.WebDriverManager - Latest version of operadriver is 2.41
    1548 [Test worker] INFO io.github.bonigarcia.wdm.Downloader - Using binary driver previously downloaded
    1550 [Test worker] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.opera.driver as C:\Users\me\.m2\re
pository\webdriver\operadriver\win64\2.41\operadriver.exe
    Starting OperaDriver 2.41 on port 37865
    Only local connections are allowed.

Socrates > Login STANDARD_OUT
    No driver specified/Wrong driver specified, default tests running on Chrome
1

There are 1 answers

3
undetected Selenium On

This error message...

INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.opera.driver as C:\Users\me\.m2\repository\webdriver\operadriver\win64\2.41\operadriver.exe
    Starting OperaDriver 2.41 on port 37865
    Only local connections are allowed.

Socrates > Login STANDARD_OUT
    No driver specified/Wrong driver specified, default tests running on Chrome

...implies that though your program accessed the OperaDriver as per system property configuration but due to mismatch in driver specification Chrome Browser was invoked.

Your main issue is though you have set the system property browser to opera still within initializeBrowser() method:

DriverType driverType = DriverType.CHROME;

Solution

Change the initializeBrowser() method as follows:

public WebDriver initializeBrowser() {
    DriverType driverType = DriverType.OPERA;

    try {
        String browser = System.getProperty("browser").toUpperCase();
        driver = DriverType.valueOf(browser).getWebDriverObject();
    } catch (Exception e) {
        System.out.println("No driver specified/Wrong driver specified, default tests running on Chrome");
        driver = driverType.getWebDriverObject();
    }

Update

Now as you are seeing the error as:

org.openqa.selenium.WebDriverException: unknown error: cannot find Opera binary

To solve this issue you can follow the discussion selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and Python