Not able to automate Opera browser through Selenium WebDriver - selenium-webdriver

I'm automating a web application which runs in 3 browsers, IE, Mozilla and Chrome.
Now when I try to run the same code in Opera with different capabilities, it opens Opera browser but in URL only data; is displayed and my tests are not running.
Here is my sample code:
DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();
System.setProperty("webdriver.opera.driver", "C:\\Important\\Test\\web\\src\\test\\resources\\operadriver.exe");
driver = new OperaDriver(capabilities);
driver.manage().window().maximize();
I'm getting following error:
org.openqa.selenium.WebDriverException: Opera not reachable (Driver info: OperaDriver=0.2.0 (ba47709ed9e35ce26dbd960fb5d75be104290d96),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)

I tried this with Windows 10, Selenium 3.5.2, Opera 52.0 and OperaDriver 2.35 and the following code works for me.
DesiredCapabilities capablities=DesiredCapabilities.opera();
System.setProperty("webdriver.opera.driver", "C:\\automation\\opera\\operadriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Program Files\\Opera\\launcher.exe");
capablities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
OperaDriver driver = new OperaDriver(capablities);
driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys("how to use opera with selenium");

Please Try with
DesiredCapabilities capabilities = DesiredCapabilities.opera();

Related

This site can't be reached error while trying to run selenium WebDriver script with selenium docker chrome node

I am trying to run selenium tests on docker with selenium docker chrome node. We are running this on windows 7. Since docker does not support windows 7, we are using vagrant to create linux box and then run selenium hub and selenium node/chrome using docker on the linux box.
When I try to run selenium script using below code, I get "This site can't be reached" error. However chrome session gets created successfully and driver launches the website. But the site displays error as "This site can't be reached"
ChromeOptions options = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
driver.get("http://www.google.com");
My company is using proxy server. I have set the proxy settings in vagrant vm box and docker containers also. So when I use "curl www.google.com" on linux box and docker selenium containers,I get the response back successfully.
When I can launch the website successfully on containers and linux box, I am not sure why website is not rendered when launched through selenium WebDriver.
I have tried launching the WebDriver with proxy settings as below but same error is present
Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.MANUAL)
proxy.setHttpProxy("<username>:<password>:<proxy_url>)
ChromeOptions options = new ChromeOptions();
options.setCapability("proxy", proxy);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
driver.get("http://www.google.com");

Insecure connection error in Firefox using Selenium webdriver using java

FF: 52.6 ESR version
Selenium : 3.5.2
Gecko driver : v0.15
FirefoxProfile profile = new FirefoxProfile();
System.setProperty("webdriver.gecko.driver", "D:/geckodrivers/geckodriver-v0.15.0-win64/geckodriver.exe");
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
driver = new FirefoxDriver(profile);
I am using this code and still getting insecure connection error. If I use capabilities, the url itself is not opening in FF browser. Issue not replicating in Chrome and IE.

Get error org.openqa.selenium.firefox.NotConnectedException when running the selenium code

getting the below error
org.openqa.selenium.firefox.NotConnectedException
Firefox : 32.0
Eclipse : Version: Neon.1a Release (4.6.1)
Upgrade your firefox You need to install geckodriver from this link:
Gecko driver download from here
and then set the setProperty()
System.setProperty("webdriver.gecko.driver", "E:\\software and tools\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
If you are using selenium jar 2.53 and browser firefox 45.0, then no need to set gecko driver:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");

latest chrome, firefox browsers are not working with selenium 3.0

I am using firefox 48 and chrome Version 52.0.2743.116 m (64-bit) with selenium webdriver 3.0. Used geckodriver for firefox also.
System.setProperty("webdriver.firefox.marionette", "D:\\Software\\geckodriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();//for firefox
System.setProperty("webdriver.chrome.driver", "D:\\Software\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();//for chrome
I am getting following error:
Unable to connect to host 127.0.0.1 on port 7055 (in case of
firefox)
Null pointer exception (in case of chrome)

How to use OperaChromiumDriver for opera version >12.X

I understand that to work on opera versions > 12.X, Operachromiumdriver has been developed. At the same time I couldn't get this to work. I downloaded the windows version of operachromiumdriver.exe from https://github.com/operasoftware/operachromiumdriver/releases but to no avail. Can someone help me with this . Please tell me if my understanding is right.
Thanks
I have found the solution running opera 25+ using OperaChromiumDriver.exe.
Install Opera 25+ (I installed Opera 25)
Download OperaChromiumDriver https://github.com/operasoftware/operachromiumdriver/releases
Extract the zip file to a location on the computer
Use the following code to open Opera
System.setProperty("webdriver.chrome.driver", "C:/Users/user/Downloads/operadriver-0.1.0-win32/operadriver-0.1.0-win32.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys("Selenium");
I have used new ChromeDriver(). This will start Opera since we are using OperaChromiumDriver. I think this is because the new Opera is based on Chromium and OperaChromiumDriver is a WebDriver implementation derived from ChromeDriver [See https://github.com/operasoftware/operachromiumdriver].
Hope this helps you.
OperaChromiumDriver now works with Opera 26+ but only with a remote instance so far... Download and launch the appropriate binary from
OperaChromiumDriver Binary Releases
They have examples for Desktop versions in python but here's what worked for me in Java. Many ChromeOptions do not work though it says they should... you will have to test to know for sure but the setBinary does work.
DesiredCapabilities capabilities = DesiredCapabilities.opera();
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/opera");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capabilities);
Operachromiumdriver
Download selenium Drivers. As their is no direct opera driver, OperaChromiumDriver is based on ChromeDriver, so we are Using ChromeOptions to set binary location of operadriver.exe
Chromium-based versions of Opera starting from version 26.
String operaChromiumDriver = "E:\\Drivers\\operadriver.exe";
String operaBrowserLocation = "C:\\......\\opera.exe"
System.setProperty("webdriver.opera.driver", operaChromiumDriver);
ChromeOptions options = new ChromeOptions();
options.setBinary(operaBrowserLocation);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
OperaDriver browser = new OperaDriver(capabilities);
WebDriver driver =browser;
driver.get("https://in.yahoo.com/");
thanks to Lukus Answer(1) to complete my work.

Resources