Automating mobile browser with Selenium - google-chrome

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

Related

How to resolve window.chrome.runtime with webdriver

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);

java - Selenium WebDriver failed to create chrome process

So I have been trying to make a program that can interact with a webpage to input data. I ideally wanted to use Chrome so I tried to set up Selenium WebDriver and ChromeDriver.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Chrome {
public static void main(String[] args) {
//Set chromedriver path
System.setProperty("webdriver.chrome.driver","C:/Users/Username/Desktop/Comp Sci work/chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Open Google
driver.get("http://www.google.com");
// Maximize browser
driver.manage().window().maximize();
}
}
I seem to have set up the external JARs correctly as I can import them with no problem. The problem is for some reason the Chrome process cannot be created. I thought this might've been because there was already a Chrome process open but no. I still got the same error when I killed the process.
I then tried to set reset the path to Chrome, as the default one might've been different to mine, but still no luck.
public class Chrome {
public static void main(String[] args) {
//Set chromedriver path
System.setProperty("webdriver.chrome.driver","C:/Users/Username/Desktop/Comp Sci work/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
// Open Google
driver.get("http://www.google.com");
// Maximize browser
driver.manage().window().maximize();
}
}
The error message is:
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e)
on port 43997
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown
error: Failed to create a Chrome process.
(Driver info: chromedriver=2.41.578737
(49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 199 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-
02T20:05:20.749Z'
As the chromedriver seems to start fine the problem is simply in creating the chrome process but I can't seem to find out why. Any help would be appreciated(Also tips about my post formatting, as this is my first post). Thanks
I meet this problem today,and solved it finally.it's because the chrome run as Administrator.so java can't start it.
Google Chrome Properties->Compatibility->not run as administrator
(for Mac) Change binary path from
/Applications/Google\ Chrome.app
..to:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

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

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)

Coded UI Test Selenium Chrome Driver

Selenium chromedriver;
The open chrome driver window displays:
Starting ChromeDriver (v2.8.241075) on port 10820
[8804:7492:0110/155544:ERROR:chrome_views_delegate.cc(176)] NOT IMPLEMENTED
[8804:7492:0110/155544:ERROR:desktop_root_window_host_win.cc(746)] NOT IMPLEMENTED
[8804:7492:0110/155544:ERROR:desktop_root_window_host_win.cc(746)] NOT IMPLEMENTED
Windows 8
ChromeDriver 2.8
Selenium 2.39
Chrome version 32.0.1700.102 m
Coded UI Test;
BrowserWindow.CurrentBrowser = "chrome";
var browser = BrowserWindow.Launch(new Uri("http://www.google.com"));
...
To run a chrome driver refer below code.
You can download the driver from
http://chromedriver.storage.googleapis.com/index.html
Step 1 :
System.setProperty("webdriver.chrome.driver",driverPath+"\\chromedriver.exe");
Step 2
ChromeDriver driver = new ChromeDriver();
driver.get(YOUR_URL_HERE)
In C#, you have to write following code:
IWebDriver driver = new ChromeDriver("fullpath to chrome driver exe");
driver.Navigate().GoToUrl("http://www.google.com");
You can download the Chrome Driver from this URL:
https://sites.google.com/a/chromium.org/chromedriver/downloads
Change the url to https://www.google.com.
Right now you are using http://www.google.com