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);
Related
We just ran into a problem in our test automation infrastructure. The problem is that Windows defaults to a very small screen size (I assume 800x600) while running from Jenkins. Then if the website under test doesn't support such a small resolution without overlapping UI elements, the browser will fail some tests for items that are no longer visible. How can we solve this?
It would be best maximize your window as soon as you instantiate your web driver instance.
I don't know the setup of your code but please try adding the following line after you've created an instance of the web driver you wish to use:
Java
driver.manage().window().maximize();
C#
_driver.Manage().Window.Maximize();
Python
driver.maximize_window()
Ruby
#driver.manage.window.maximize
The above may not work in Chrome - if this is the case, please use:
ChromeOptions options = new ChromeOptions();
options.addArgument("--start-maximized");
driver = new ChromeDriver(options);
As per #Ardesco & #Fenio comments - you can also set a specific dimension using:
driver.manage().window().setSize(new Dimension(1920,1080));
driver.manage().window().fullscreen()
Within your driver setup you can change the browser window size using the following in C#
driver.Manage().Window.Size = new System.Drawing.Size(width: 1600, height: 1200);
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 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'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.