How to resolve window.chrome.runtime with webdriver - google-chrome

I am getting undefined for window.chrome.runtime when open the chrome browser with selenium webdriver while on manually open the browser, we are getting object for window.chrome.runtime.
Is there any way to use Javascript's window.chrome.runtime with selenium webdriver?
I tried with following option but its didn't work for me.
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir=C:\\Users\\ChhaviSinghal\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(options);

Related

ChromeDriver - headless option causes WebDriver to crash, when applied over added extension

Our framework uses “basic authenticator” extension that automatically takes care of authentication dialogs. The problem is that when attempting to run tests in headless mode, chromedriver crashes with following error:
org.openqa.selenium.WebDriverException: unknown error: failed to wait for extension background page to load: chrome-extension://paomkgjogbncmncdnconbommejfdhaoh/_generated_background_page.html
from unknown error: page could not be found: chrome-extension://paomkgjogbncmncdnconbommejfdhaoh/_generated_background_page.html
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(“authenticator”));
options.setHeadless(true);
WebDriver chrome = new ChromeDriver(options);
Chrome doesn't accept extensions in headless mode.
Consider switching the extensions off, or using Firefox.

Chrome browser doesn't open in kiosk mode using Selenium WebDriver

I am using Selenium WebDriver with chrome browser and for whatever reason, it doesn't open in kiosk mode. This used to work, not sure why it stopped.
This is my code:
private IWebDriver GetChromeDriver(BrowserConfigurationOptions browserConfigOptions)
{
var options = new ChromeOptions();
options.AddArguments("disable-infobars");
options.AddUserProfilePreference("credentials_enable_service", false);
if (browserConfigOptions.KioskModeForChrome)
options.AddArgument("--kiosk"); //options.AddArgument("--enable-kiosk-mode");
LogChromeOptions(options);
return new ChromeDriver(options);
}
This is my environment:
Chrome 66
Selenium WebDriver v 3.11.2
Chromedriver version 2.38.0.1 from this Nuget package
I've tried passing in --kiosk and --enable-kiosk-mode with no success.
To initialize the Chrome Browser in Kiosk Mode you need to pass the following argument through an instance of ChromeOptions class:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
return new ChromeDriver(options);
Note A : As per Java Doc, it is arguments are passed as addArguments()
Note B : As per Peter Beverloo
--kiosk:
Enables kiosk mode. Please note this is not Chrome OS kiosk mode.
Sample Code(Java):
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
Browser Snapshot:
After seeing that everyone had this working except me, I started digging further. After digging into the code I found
Driver.Manage().Window.Maximize();
being called after initialization of the driver. After removing this line of code, I was able to open Chrome in kiosk mode with the solution above.
Config issue as Chrome 66 is supported by Chromedriver 2.38 and you're using 2.18
Please update from below.
http://chromedriver.chromium.org/downloads

Automating mobile browser with Selenium

Can we automate chrome browser on mobile with Selenium.
Without using the Appium.
That is I need to automate browser on mobile without using appium but selenium.. So Is there a way to do same in JAVA..
Download jar for Android driver here:
https://github.com/selendroid/selendroid
Start is up from command line:
$ java -jar selendroid-standalone-0.17.0-with-dependencies.jar
In your test, instantiate the driver like this:
driver = webdriver.Remote(desired_capabilities=DesiredCapabilities.ANDROID)
just instal Appium and use desired capabilities, these here are a setup for emulator with pre-set emulator call "Android", managed in Android Studio, AVD Manager.
public static void main(String[] args) throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("app", "Chrome");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.3");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("http://www.yahoo.com");
}
or if this doesn't work try this bellow:
DesiredCapabilities capabilities=new DesiredCapabilities();//DesiredCapabilities.chrome();
ChromeOptions options=new ChromeOptions();
options.setExperimentalOptions("androidPackage", "com.android.chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
I'm using latest dependancies of appium server and appium-java-client

How can I specify custom chrome arguments when launching selenium chromedriver?

In this specific case I want to use the chrome CLI switch --use-fake-ui-for-media-stream but it should work for any available chrome switch.
Any language is fine, I'd like this question to serve as documentation for how to do this in different languages.
Full disclosure: I intend to answer this for a few languages myself.
Ruby
Selenium::Webdriver.for(
:chrome,
switches: %w(
--use-fake-ui-for-media-stream
)
)
Java
ChromeOptions options = new ChromeOptions();
options.addArguments("--use-fake-ui-for-media-stream");
WebDriver driver = new ChromeDriver(options);
Python
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--use-fake-ui-for-media-stream")
driver = webdriver.Chrome(executable_path="path/to/chromedriver", chrome_options=chrome_options)

Unable to load unpacked extension into chrome using Selenium webdriver

I am new to using web driver but I have followed what was mentioned here (How can I launch Chrome with an unpacked extension?) and all that I could get from other web search.
I am trying to test an extension for chrome which I have developed but I haven't been able to figure out how to start chrome with extension loaded on it. Here is what I have till now and I would appreciate if someone could tell me the issue with the code (I was successful in launching Chrome using webdriver):
import time
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
browser = webdriver.Chrome() browser.get('http://seleniumhq.org/')
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=C:\Users\mave\Desktop\Browser_Extension_Feature\extension_v5");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
time.sleep(15)
browser.quit()
I was finally able to figure out how to run an unpacked extension and would leave this code for anyone who has similar troubles in future:
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("load-extension=C:\Users\mave\Desktop\Browser_Extension_Feature\extension_v5");
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get('http://www.seleniumhq.org/')
time.sleep(5)
browser.quit()