How to launch the REST Console URL using selenium webdriver? - google-chrome

public static void main(String args[]) throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\pugazd\\Desktop\\chromedriver.exe");
String url2="chrome-extension://cokgbflfommojglbmbpenpphppikmonn/index.html";
WebDriver driver = new ChromeDriver();
driver.get(url2);
}
I try to launch the URL with chrome browser, the browser opens with the error.
Error: The webpage at chrome-extension://cokgbflfommojglbmbpenpphppikmonn/index.html might be temporarily down or it may have moved permanently to a new web address.
Error code: ERR_FAILED.
How do I open the REST Console ?
Thanks in Advance
Thyagu

By default Chrome does not load any extensions in the window launched by Selenium. (You can verify this by loading driver.get("http://www.Google.com") and checking the list of extensions.
And obviously your extension should be loaded into Chrome, for the URL (which you tried) to work.
To enable ChromeDriver to load extensions, use
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);

Related

Selenium Webdriver throws timeout excption for chrome

I have updated version of chrome as well as WebDriver. Still getting the timeout exception. It was working properly previously but suddenly it started giving exception. It is not even reaching to test as well. If anyone has solution lease help.
Version 64.0.3282.140 (Official Build) (64-bit)
Webdriver: WebDriver.ChromeDriver.win32 2.35.0
var smth = m_driver.WaitUrl(new Regex(settings.GetSiteString("xyz") + "#/.*"));
for (int maxWait = 60000; maxWait > 0; maxWait--, System.Threading.Thread.Sleep(500))
if (m_driver.FindElement("//div[#ng-show='vm.loaded']").Displayed)
{
System.Threading.Thread.Sleep(500);
return;
}
throw new TimeoutException("Failed to wait for xyz page to load.");
Error message: The HTTP request to the remote WebDriver server for URL http://localhost:63425/session/cdc3e59/url timed out after 120 seconds.
It seems that adding the no-sandbox argument to your chrome driver options fixes the problem. I'm still trying to figure out why this fixes it.
Here is an example of how to instantiate a ChromeDriver so that it doesn't give you timeouts on pages that actually load properly.
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("no-sandbox");
var webDriver = new ChromeDriver(Directory.GetCurrentDirectory(), chromeOptions);
I found this solution in this Github thread

Execute script not working for https sites - chrome selenium webdriver

I am trying to execute a javascript as part of my testing.
Below is my chrome driver settings
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("headless");
options.addArguments("--disable-web-security");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--reduce-security-for-testing");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
driver.get("https://samplesite.com/");
And I am trying to execute a script on the site using Javascript executor.
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript(code);
This is not working due to the below error.
The page at 'https://samplesite.com/' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint 'http://localhost:8080/myapi'.
This request has been blocked; the content must be served over HTTPS.
But the same is working when I remove the headless option and execute as a visible browser with a Warning message in the console.
could someone guide me on this.
Looking at the error stack trace says it all :
The page at 'https://samplesite.com/' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint 'http://localhost:8080/myapi'.
This request has been blocked; the content must be served over HTTPS.
The URL https://samplesite.com/ was loaded with HTTPS but the jquery post script is trying to call a a webpage over HTTP
On an https webpage you can only make Jquery/AJAX Request to https webpage only
It would be interesting to know if you are specifying http or https in the Jquery Request.
You also need to ensure that as the data which you are requesting is not in the same domain, the domain providing the data must allow it with CORS or JSONP.

Selenium not starting portable chrome but local installation

I have a problem with the Selenium web driver. What I'm trying to do is to start a "portable" chrome instead of my local installation, because it has different settings.
The problem is that the portable Chrome (from PortableApps) seems to only start when using GoogleChromePortable.exe. If I use the Chrome binary directly, it will start my local installation.
With Selenium it seems that no matter what Chrome path I pass to it (GoogleChromePortable.exe or binary path), it starts my local installation.
Here is my code:
String chromePath = "M:/my/path";
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
capabilities.setCapability("chrome.binary", chromePath);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Any ideas how to be able to start my portable chrome?
Thanks
For anyone else stumbling upon this problem, here is how I managed to get the portable Chrome starting:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(binaryPath);
driver = new ChromeDriver(chromeOptions);
I'm using Python 3.7 on Windows 10 and got Chrome Portable from PortableApps.com.
comments by #mario.schlipf and #SeJaPy were helpful, but I noticed that in the newer Webdriver releases, the setbinary method has been replaced by binary_location
This is how it actually worked for me:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chromedriverpath='M:/my/chromedriver.exe'
chromePath = 'M:/my/App/Chrome-bin/chrome.exe' # <== IMPORTANT! See note below.
chromeoptions = Options()
chromeoptions.add_argument('--incognito')
chromeoptions.binary_location = chromePath
browser = webdriver.Chrome(executable_path=chromedriverpath, options=chromeoptions)
NOTE:
The chromePath variable must point to the Chrome executable in the portabilized environment.
In packages obtained from PortableApps.com, you have two executables: a GoogleChromePortable.exe in the install (actually, unpack) directory and a chrome.exe in [installdirectory]/App/Chrome-bin, the first being "just" a launcher which provides the portabilized app with a consistent environment.
As I could observe, chromedriver needs to directly interact with the "real" Chrome executable, otherwise the script will launch the browser (via the launcher) but will eventually crash with error message:
unknown error: DevTools Active Port file doesn't exist
and no browser session will be returned as a result.
This may seem obvious to many people... but it was not to me, so I decided to put this note in order to make some clarity for the less clever guys (myself included) :).
String chromePath = "M:/my/googlechromeporatble.exe path";
String chromedriverpath="M:/my/chromedriver.exe path";
ChromeOptions options = new ChromeOptions();
options.setBinary(chromepath);
System.setProperty("webdriver.chrome.driver",chromedriverpath);
driver = new ChromeDriver(options);
This will invoke portable chrome rather than local installation.
First set google chrome portable path and then invoke chromeriver.exe
Depending on the settings you have in ChromePortable, maybe you could default ChromeDriver with Capabilities & ChromeOptions?
I'm thinking especially on custom profile. If you somehow could get that from your ChromePortable and load it with default ChromeDriver?
EDIT: Maybe this could help

Selenium - Chrome is not starting when I try to load an extension

Since Firefox does not support the GWT DevMode any more, I want to switch to Chrome for developing selenium tests for my application.
However, it fails to load the GWT-dev-plugin extension. The test does not return from
driver = new ChromeDriver(capabilities);
Without configuring the extension, in works in the sense that a Chrome instance is at least started, however, without GWT plugin.
This is the way I configure the webDriver:
package the GWT plugin of your Chrome installation (described here http://www.mythoughts.co.in/2013/09/seleinum-webdriver-loading-chrome.html#.U0ZTFFfKGno)
use the path of the plugin .crx package as pluginPath in the following code
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(pluginPath));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
File driverExecutable = new File("test-selenium/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", driverExecutable.getAbsolutePath());
driver = new ChromeDriver(capabilities);
The only logging is a WARNING concerning the plugin key:
[14.899][WARNING]: Public key in crx header is different from key in manifest
key from header: ....
generated extension id from header key: godampgacipeiboepncogmjpfbgcpfba
generated extension id from manifest key: jpjpnpmbddbjkfaccnmhnkdgjideieim

How can I launch Chrome with an unpacked extension?

I'm using Selenium WebDriver to test a Google Chrome extension I'm developing. I noticed that ChromeDriver can be customised to add extensions to the instance of Chrome that it launches. This can be achieved using the AddExtension and AddExtensions methods of the ChromeOptions class.
The documentation for these methods indicates that they require extensions to be provided as crx files. Since I'm developing the extension, I don't have a crx file. I would like to be able to load the unpacked extension, but I couldn't find a method to do this.
I tried putting the extension files in a zip file and specifying this for the AddExtension method, but this caused an exception to occur since it wasn't a crx file. I also tried passing in the directory containing the unpacked files, but this produced a FileNotFoundException.
How can I do this?
I was able to achieve this by using the AddArgument method to directly pass the information to Chrome. Here's what it looks like in C#:
options = new ChromeOptions();
options.AddArgument("--load-extension=" + unpackedExtensionPath);
For packed extensions (a .crx file)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
For unpacked extensions (a local folder)
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=/path/to/extension");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
source
It may be late but for future users:
https://sites.google.com/a/chromium.org/chromedriver/extensions
The unpacked extension error popped up for me and I requested for removing the restrictions in chrome which was enforced as organizational policy. Once the restrictions were removed, I am able to run the program with out any errors. ChromeBrowser-GPO-Deny - this was the one which was removed. You can check in Settings - Extensions - Check on Developer mode and see if the load unpacked extensions is checked once the restrictions are removed. You should be good then. All the above will work only when the chrome is not restricted.
In Python3 it can be done like this:
from selenium.webdriver import Chrome, ChromeOptions
options = ChromeOptions()
options.add_argument("load-extension=/path/to/unpacked_ext")
driver = Chrome("/path/to/chromedriver", options=options)
# (optional) Look at the uploaded extension
driver.get("chrome://extensions")
Here is apython example using webdriver_manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
# loading the extension Edit-This-Cookie
options.add_argument("--load-extension=./Edit-This-Cookie")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
driver.get("https://google.com")
The Selenium documentation has an example like this for a packed ( not unpacked) extension:
capabilities.setCapability("platform", "Windows 8" );
capabilities.setCapability("version", "10");
capabilities.setCapability("name", testname);
capabilities.setCapability("screen-resolution", "1280x1024");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
if (isLocal) driver = new ChromeDriver(capabilities);