I need to start Firefox / Chrome using remote webdriver with a specific browser language. I know how to do it while running locally. But is it possible to start a remote webdriver with specifying browser language.
This is how object creation done is RemoteWebDriver,
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), DesiredCapabilities.firefox());
Profiller is the key here,
var fp = new FirefoxProfile();
fp.SetPreference("intl.accept_languages", "en-au");
desiredCap.SetCapability(FirefoxDriver.ProfileCapabilityName,fp.ToBase64String());
your code seems specific to chrome so you can use this, I hope this might help you,
var options = new ChromeOptions();
options.AddArgument("--lang=zh"); // this sets US english
desiredCap.SetCapability(ChromeOptions.Capability, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), desiredCap.chrome());
Possible duplicate of How to set Browser Language using RemoteWebDriver
Related
Hi i am trying to connect to remote webdriver on browserstack using Selenium but whenever the page loads in Chrome and Firefox i get a security message (see images below).
my URL is starting with https:// (when i manually open the browser i have to accept the certificates and continue before the webpage loads)
i have added this line to my code but it does not seem to make any difference:
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, "true");
capability.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
NOTE: This issue only occurs then the tests are run on the GoCD pipeline. when running on intellij it all works fine
error:
org.openqa.selenium.WebDriverException: Reached error page: about:neterror?e=nssFailure2&u=https%3A//transport....
in chrome i see this:
and in firefox i get a similar message:
Can you try adding something as below and test:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("ignore-certificate-errors");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
options.addArguments("--test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-gpu");
chromeOptions.AddArguments("window-size=1980,1080");
Driver = new ChromeDriver(chromeOptions);
i have found the problem for anyones future reference.
This is because DNS requests were not forwarded for our host name on GocD.
DesiredCapabilities 'Chrome' > doesn't work with 'Selenium Grid.
I have a hub setup correctly and a node
however when trying to point Chrome browser to one of the nodes it doesn't work.
Current code:
case "chrome":
if (null == webdriver) {
System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY);
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("55.0.2883.87 m");
capability.setPlatform(Platform.WINDOWS);
webdriver = new RemoteWebDriver(new URL("http://172.16.1.48:5555/wd/hub"),capability);
}
break;
Exception:
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=55.0.2883.87 m, platform=WINDOWS}], required capabilities = Capabilities [{}]
Couple of things :
On the node side, please ensure that the chromedriver (for chrome browser), geckodriver(for firefox browser) and IEDriverServer(for IE) are all available in the PATH variable and can be invoked by just opening up a command prompt and typing their names.
When you do DesiredCapabilities capability = DesiredCapabilities.chrome(); it automatically sets the browser name appropriately. So you don't need to set it again via capability.setBrowserName("chrome"); (So you can remove it off).
Unless and until you have explicitly set a browser version at your node level via the nodeConfig json file, please remove capability.setVersion("55.0.2883.87 m"); because this causes your test to ask for a node that can support chrome 55 version, but if you don't specify the same versioning at your node, your grid will turn down your new session request stating it cannot find the required desired capabilities.
Going by your screenshot it looks like your hub is running on localhost listening to the port 4444 but your code shows as if you are trying to connect to the node directly. So please change webdriver = new RemoteWebDriver(new URL("http://172.16.1.48:5555/wd/hub"),capability); to `webdriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);
Once you have taken care of these items, your issue should get fixed.
From what I understand so far, Chrome Driver always starts without any stored browser cookies.
I need the driver start with all the cookies stored by Chrome.
I wonder if there is any way to start the driver with the cookies that are already stored? I'm using C# with .net 4.5.
Yes we can do it by invoking saved chrome profile just like firefox profile. below are steps i noted when i am doing bit back ago
in Java, we can do it by using ChromeOptions and Chrome Profile. In chrome navigate to chrome://version/ It will display profile path and Executable path.
As per my working on this, The profile path is \Local\Google\Chrome\User Data\Profile 3 This is displaying what is displayed when i navigate to chrome://version/ in normal chrome browser. In this profile, i navigated to stackoverflow and saved credentials. So used below code
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\poi-3.12\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("user-data-dir=C:\\Users\\murali\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
//WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com/");
As per my understanding, i excepted stackoverflow.com page displayed as logged in. but for first time, i am not logged in. so cross checked with chrome://version/ in chrome opened by driver, profile path is displayed as
\Local\Google\Chrome\User Data\Profile 3\Default . then logged manually in that profile it self, which is opened by webdriver and executed gain by closing it.
Finally, page is displayed as logged in. So it may be in java, i hope it will helps you to try in C# .
I want to open Chrome on the client side using selenium webdriver. I have a piece of code and it works fine for single system, but I can't access it in another system.
I am using selenium-server-standalone-2.44.0.jar, chromedriver for the purpose.
This is the code I use to open browser:
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver=new ChromeDriver();
Is the ChromeDriver on the other system in the same place as on the single system?
Try something like the following (in java):
String currentDir = System.getProperty("user.dir");
String chromeDriverLocation = currentDir + "/../tools/chromedriver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromeDriverLocation);
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-plugins");
options.addArguments("disable-extensions");
WebDriver chrome = new ChromeDriver(options);
chrome.get("http://www.google.com");
Selenium webdriver can be used in different languages.
I can give you an example.
A web application is developed by using python in back-end and front-end is built up with html and a interpreted programming language like javascript. If we use selenium webdriver with python then browser opens at server side. and if we use selenium with javascript then browser opens at client side.
Before running selenium there is a requirement that a certain certificate needs to be imported. On importing the same the execution starts as expected.
But each and everytime the execution re-starts (a new test suite is run), the certificate is no longer present in Firefox and hence fails as the certificate is not imported.
Is there any setting in selenium that will prevent the certificate from being unimported before the execution starts everytime/
-S
Create a new Firefox profile, import all your certificate in that profile and then use that profile while instantiating Firefox webdriver instance.
To create new Firefox profile refer this link.
Once you import your certificate to newly created profile, use below code to create Firefox webdriver instance:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile profile = profile.getProfile("your_profile_name");
WebDriver driver = new FirefoxDriver(profile);
There are many ways to setup a FireFox profile in Selenium. You can setup a specific profile to use as #Surya mentioned above, or you can set setAcceptUntrustedCertificates to true for your profile:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
WebDriver driver = new FirefoxDriver(profile);
Other methods that I've seen using a RemoteWebDriver involve wrapping your profile in DesiredCapabilities which also has a flag for accepting SSL certificates:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(capabilities);
Without seeing how you've setup your profile, we're only taking shots in the dark. Hopefully one of these suggestions works for you.