Remote WebDriver UnreachableBrowserException: Could not start a new session - selenium-webdriver

I got this exception for all browsers. For example, I create a remote webdriver on chrome like this:
caps = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
caps.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new RemoteWebDriver(new URL("http://myIP:5555/wd/hub"), caps);
And I got UnreachableBrowserException as follow:
org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
But I check my selenium hub at http://myIP:4444/grid/console, everything is fine, the node is stil registered. I then check my node at http://myIP:5555/wd/hub/static/resource/hub.html, I still can click "Create Session" to create a session for all browsers.
I just got this exception today, it still worked few days ago. I am using Selenium 3.11.0, IntelliJ 2017.3, all drivers and browsers are latest versions.
I googled here, but I can't find a solution for this while my gird is still running. Any help much appreciated.

The error says it all :
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
The current implementation of Selenium while invoking RemoteWebDriver supports the ChromeOptions and you can use the following code block :
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
webDriver = new RemoteWebDriver(new URL("http://myIP:5555/wd/hub"), options);
Update
As per your comment update the documentation at seleniumhq-documentation is yet to be updated. Here are the relevant bytes from the Selenium Release Notes :
Selenium v3.5.0 :
* Start making *Option classes instances of Capabilities. This allows
the user to do:
`WebDriver driver = new RemoteWebDriver(new InternetExplorerOptions());`
Selenium v3.6.0 :
* All `*Option` classes now extend `MutableCapbilities`
`new RemoteWebDriver(new ChromeOptions());`
Selenium v3.7.0 :
* Migrated from using `DesiredCapabilities` to either
`MutableCapabilities` or (preferably) `ImmutableCapabilities`.

Related

How to attach a Selenium ChromeDriver to an embedded CefSharp browser in a WPF application?

I have a ChromiumWebBrowser control in my MainWindow.xaml:
<cefSharp:ChromiumWebBrowser x:Name="chromiumBrowser" Address="https://www.github.com/"/>
and I'm trying to drive it by attaching a Selenium ChromeDriver to it:
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = AppDomain.CurrentDomain.FriendlyName;
options.AddArguments("disable-extensions");
options.AddArguments("disable-plugins");
ChromeDriver chromeDriver = new ChromeDriver(options);
chromeDriver.Url = "http://www.reddit.com";
Is this a correct approach? It seems to nearly work as the embedded control flashes once when the driver attempts to connect to it but then I get the following error from the ChromeDriver console:
[1006/220430.356:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[1006/220430.357:ERROR:cache_util.cc(139)] Unable to move cache folder GPUCache to old_GPUCache_000
EDIT
Apparently attaching a driver using options.BinaryLocation will unfortunately always launch a new instance of the executable. From the comments below, I gathered that the correct way would be to attach the driver through a debug port. So I create my browser control through code:
CefSettings settings = new CefSettings();
settings.RemoteDebuggingPort = 9222;
settings.UserDataPath = "C:/Temp";
Cef.Initialize(settings);
browserControl = new ChromiumWebBrowser("chrome://version");
But when I try to attach to it:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--remote-debugging-port=9222");
ChromeDriver driver = new ChromeDriver(options);
driver.Url = "http://www.reddit.com";
The error is now:
System.InvalidOperationException: 'session not created from disconnected: unable to connect to renderer (Session info: chrome=85.0.4183.121) (SessionNotCreated)'
This could be due to mismatching chrome versions as CefSharp only supports up to v84 at the moment. I'm using a v84 chromedriver so I don't know where this 85 warning comes from.
After sustaining some massive hair loss, I found out that this works:
CefSettings settings = new CefSettings();
settings.RemoteDebuggingPort = 9222;
settings.UserDataPath = "C:/Temp";
Cef.Initialize(settings);
browserControl = new ChromiumWebBrowser("chrome://version");
And this is how to gloriously attach to the embedded ChromiumWebBrowser:
ChromeOptions options = new ChromeOptions();
options.DebuggerAddress = "localhost:9222";
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
ChromeDriver driver = new ChromeDriver(service, options);
The trick was to use ChromeOptions.DebuggerAddress instead of ChromeOptions.AddArguments("--remote-debugging-port=XXXX")

selenium browser launch by octopus [duplicate]

The release notes for ChromeDriver 2.33 says that ""Fixes a bug which caused Resizing/Positioning Window commands to fail on Chrome 62+" however this still seems to be an issue when i am using Chrome 62+ browser. Maximizing chrome window using chrome driver results in below exception. Does anyone know a solution please?
Another thing i noticed is, though i installed latest chromedriver (v2.33) from https://chromedriver.storage.googleapis.com/index.html?path=2.33/, the log printed below says Driver info: chromedriver=2.25.426923 !!
Exception in thread "main" org.openqa.selenium.WebDriverException:
unknown error: cannot get automation extension from unknown error:
page could not be found:
chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=62.0.3202.62) (Driver info:
chromedriver=2.25.426923
(0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT
10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
There are exactly 2 issues.
As you mentioned, you have installed latest chromedriver (v2.33) but the log printed below says Driver info: chromedriver=2.25.426923, this issue must be addressed first. You can consider to manually kill all the dangling chromedriver.exe tasks from the Task Manager. Additionally you can consider to use CCleaner to wipe out all the rotten OS stuffs from your system. Take a system reboot if required. Finally ensure that what ever the absolute location of chromedriver.exe you are using within System.setProperty() ensure that the chromedriver binary is of version 2.33.
Finally, it is suggested to use ChromeOptions class to maximize the Web Browser as follows:
System.setProperty("webdriver.chrome.driver", "C:\\your_directory\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(opt);
driver.get("https://google.com");
Here are some of the alternatives which may solve your question:
Using maximize() from WebDriver.Window interface :
driver.manage().window().maximize();
Using setSize(Dimension targetSize) from WebDriver.Window interface:
driver.manage().window().setSize(new Dimension(800, 600));
Using addArguments("--start-maximized") through ChromeOptions:
chromeOptions.addArguments("--start-maximized");
Using addArguments("--window-size=1920,1080") through ChromeOptions:
chromeOptions.addArguments("--window-size=1920,1080");
Using executeScript() from JavaScriptExecutor interface:
((JavaScriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");
You can find a related discussion in Chrome - org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension at driver.manage().window().maximize();.
I believe there were some old chrome driver processes running in backend and same were being picked up when it was invoked via code. I deleted all processes instances, deleted old version of chrome driver, added the new 2.33 version and it worked. Thanks all for your suggestions.
I think the reason behind it may be your chrome version. Try again with updating your chrome browser. I have faced this type of issues for compatibility between chrome browser & the driver
Use class ChromeOptions.
System.setProperty("webdriver.chrome.driver", "h:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get(url);

Selenium Secure Socket Layer Issue in Selenium 3

How could I handle ssl certifiaction error in selenium 3 and above for firefox 49+.
It will be helpful if anyone could answer. Thanks in advance
For chrome :
DesiredCapabilities SSLErr = DesiredCapabilities.chrome ()
SSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true)
WebDriver driver = new ChromeDriver (lSSLErr);
or
ChromeOptions option= new ChromeOptions();
option.addArguments("headless");
option.addArguments("ignore-certificate-errors");
WebDriver d=new ChromeDriver(option);
For Firefox
FirefoxProfile profileSSL = new FirefoxProfile();
profileSSL.setAcceptUntrustedCertificates(true);
profileSSL.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(profileSSL)
Hi Actually none of the above worked for me, I am using Selenium 2.35.1 and Firefox 49. So I used try catch method, where I am catching that WebDriverException and clicking on exception using selenium and AutoIT to close the window based popup

Selenium Webdriver + Java - How to configure automatic proxy configuration URL for firefox?

I'm trying to configure my FirefoxDriver to use automatic proxy configuration URL. I am failing to do so.
My code looks like this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 2);
profile.setPreference("network.proxy.autoconfig_url", "http://10.203.193.52/Proxy-cmv.pac");
WebDriver driver = new FirefoxDriver();
I am not receiving any kind of errors but the connection is not working for this browser. When checking Options > Advanced > Network > Connection Settings from Firefox menu, proxy is set to "Use system proxy".
You need to use that profile, because now you just create it.
So, change:
WebDriver driver = new FirefoxDriver();
to
WebDriver driver = new FirefoxDriver(profile);

Issue while handling proxy prompts with the Firefox driver

I am facing issue with the proxy prompts for firefox browser with version 17.
I tried the steps mentioned in this link. But still am getting the prompts.
Also referred selenium document for using proxies, but unable to succeed.
I need to use FF17 only as per my project req and am using selenium 2.28.
My company proxy addr is proxy.comp_name.com port: 8080.
I am not getting any proxy prompts while doing manually.
While running multiple tests prompt will be displayed arbitrarily.
Any updates on the below issue?
code used to launch the driver with the default firefox profile
FirefoxProfile profile = new ProfilesIni().getProfile("default");
DesiredCapabilities dCap = DesiredCapabilities.firefox();
dCap.setCapability(FirefoxDriver.PROFILE, profile);
driver = new FirefoxDriver(dCap);
code used to launch the driver with the new profile:
String PROXY = "proxy.abc.com:8080";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabailities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);
Also I tried by setting Preferences to the firefox profile, but still am getting the proxy prompts..
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("network.proxy.type", ProxyType.SYSTEM.ordinal());
firefoxProfile.setPreference("signon.autologin.proxy" , true );
firefoxProfile.setEnableNativeEvents(false);
desiredCapabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
return new FirefoxDriver(desiredCapabilities);
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("");
// We use firefox as an example here.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
// You could use any webdriver implementation here
WebDriver driver = new FirefoxDriver(capabilities);

Resources