I'm trying to load my Chrome profile for use with Selenium WebDriver but it doesn't work and always defaults to a new one. I tried the codes provided from here.
Is there any workaround or fix? I'd like to run ChromeDriver with customized extensions, options and whatnot since command line flags and ChromeOptions have restricted functionality.
Also, I'm having another issue about loading preconfigured extensions.
I had the same problem.But I did something like this and it worked.
String userProfile= "C:/Users/"your user"/AppData/Local/Google/Chrome/User";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=" + userProfile);
driver = new ChromeDriver(options);
Please let me know if it work also for you.
Related
i am currently going through selenium webdriver on the selenium wbesite.
There is a section of the website that talks about the "Change user agent" and explains how to do it: https://docs.seleniumhq.org/docs/03_webdriver.jsp#chapter03-reference However, no "real" or "mock" example is given showing this in "action".
So, I was wondering if anyone here, would perhaps have or be able to share a code snippet, with the project included, showing this "in action"? A mock project, you may have or designed yourself to practice this, should suffice.
I have already made a lot of research online, trying to find an example of this, but no success.
From the link you provided, you can change the User-Agent with below code:
Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("general.useragent.override", "user-agent-string");
WebDriver driver = new FirefoxDriver(profile);
Chrome:
ChromeOptions chrome = new ChromeOptions();
chrome.addArguments("user-agent=YOUR_USER_AGENT");
It's Java but you can easily switch to any selenium-supported language because all of them implement FirefoxProfile and ChromeOptions
I am using Selenium for testing. I noticed a different behavior starting Chrome manually and starting it with selenium. After a lot of investigation I broke the problem down to JavaScript's window.chrome.runtime which is undefined if started with selenium.
After some research on Google I have found people facing similar issues, but none of their solutions worked for me.
I have tried so far to remove the test-type switch:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
Are there any other ways I can make it work?
Answer which did the job for me was at https://groups.google.com/forum/#!topic/chromedriver-users/7wF9EHF2jxQ
Code snippet:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
Selenium does not start browser with an existing browser profile, it create a temporary one, every single time. So it does not need to send js to check any installed plugins. To avoid the undefined runtime, use an existing browser profile.
ChromeOptions options = new ChromeOptions();
// edit this path
options.addArguments("user-data-dir=C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(options);
I am working on making a tiny Java app of which needs to open a Firefox browser in hidden mode and also have it be muted.
As you can see by the code below, I have found a way to have the browser be hidden. However I am having some issues figuring out, how to mute the browser and whether it is actually even possible to do.
Considering the following answer I figured it may be possible, I know the answer is for Python but it's using the selenium webdriver, however for Chrome, where I need it for Firefox.
I tried to insert the following line firefoxBinary.addCommandLineOptions("--mute-audio"); however that didn't seem to work.
The following is what I currently have.
WebDriver driver;
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", driverPath);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
driver = new FirefoxDriver(firefoxOptions);
After further investigation, the following code fixed the issue of muting Geckodriver in Java, using Selenium.
I added this code below the firefoxOptions.setBinary(firefoxBinary); line of my script above.
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("media.volume_scale", "0.0");
firefoxOptions.setProfile(firefoxProfile);
In my application, I need to write code for enabling/disabling of browser pop up for some scenario. I searched on wed and tried many solutions but non of them seems to be working.
It will be very helpful for everyone if some one can provide solution of this problem in one discussion thread.
I am able to handle that is Chrome but I other not seems to be working. My code is:-
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
options.addArguments("chrome.switches","--disable-extensions");
driver = new ChromeDriver(options);
I've been looking for a while and still haven't found anything. When I run my Selenium tests from within Eclipse, it opens up a Firefox browser which always has English as its default locale. Changing default browser settings doesn't change the fact that each new browser opened by Selenium has an English locale.
I haven't found any way in the API to set something other than English as my locale. I've tried setting the locale as a VM parameter for the Selenium server, I've tried setting it for my tests.
There's got to be some obvious way of doing this that I'm missing that will result in easy rep for you. :) Any thoughts?
My idea to solve this...
Create Firefox Profiles and open them with Selenium. You can modify them for your needs.
Selenium Documentation
By using specific profiles you can avoid this issue. It is not a "nice and clean" Solution..but it works...at least for me.
Now you may use the following snippet for ChromeDriver (in Scala):
private def createDriver(): RemoteWebDriver = {
val prefs = new util.HashMap[String, Any]()
prefs.put("intl.accept_languages", "en")
val options = new ChromeOptions()
options.setExperimentalOption("prefs", prefs)
options.setBinary(chromePath)
new ChromeDriver(options)
}