I'm on my way upgrading our tests from selenium 2 to 3. There is a final line I cannot migrate setEnableNativeEvents(false) in
FirefoxProfile profile = ...
profile.setEnableNativeEvents(false);
webDriver = new FirefoxDriver(...);
I really don't know why this line was added in the past, but I'm a little afraid what happens if I remove it.
Is there a selenium 3 equivalent to this? Does it have any effect to set this to false, or is false the default?
As you mentioned you were upgrading your tests from selenium 2 to 3, I can see setEnableNativeEvents(false) was in practice during Selenium-RC days e.g. selenium-server-standalone-2.0rc2 and Selenium v2.7.0 even, as follows:
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
The purpose of using setEnableNativeEvents(true) was to enable the UI elements those were disabled in Firefox [Browsers]. There were traces of issues occuring with this setting on OS : Ubuntu 11.04 and other OS.
You can have a detailed look at this thread.
The current Documentation of FirefoxProfile clearly mentions about shouldLoadNoFocusLib()
shouldLoadNoFocusLib()
The method shouldLoadNoFocusLib() returns whether the no focus library should be loaded for Firefox profiles launched on Linux, even if native events are disabled.
Returns : Whether the no focus library should always be loaded for Firefox on Linux.
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);
Getting following error in selenium tests
POST /session/ee1b9201-dadc-7446-b753-0a418a230d30/moveto did not match a known command
What i've done is
Actions resetView = new Actions(driver);
resetView.moveToElement(el).perform();
Environment:
Firefox v47.0
Webdriver 3.0.0-beta2
This is entirely expected. No releases of GeckoDriver (Marionette) support the Actions class. It is one of the top priorities of Mozilla's team developing Marionette.
There is an issue that Selenium tracks, that is blocked by the Marionette issue.
Since the issue it's over 3 weeks old, and looking at their commit log, I wouldn't hold my breath for a patch anytime soon.
If you can use Firefox 47.0.1, because in Firefox 47.0 they had another bug, you can use the old WebDriver API that works (not Marionette). From 48 it stopped working, because you're supposed to use Marionette. Yes, that Marionette that is not finished.
If you must test on Firefox, I recommend you should stick to Firefox 47.0.1, Selenium 2.latest, eventually throw them in a docker image, and run like that.
That's what I do at least for Germanium, until it will hopefully eventually work also for Marionette.
I have seen this question asked in different ways but none of the answers provided will fix my problem.
I am trying to automate a Firefox plugin installation.
1) I have used Java Selenium and AutoIT and it logs into a web application.
2) After clicking on the proper links it will install the plugin.
3) Once the plugin is installed I noticed that it is installed into an anonymous profile instead of "MyProfile" the one I manually created and had my code initiating it using webdriver (see code snippet below on what was used.)
4) This poses a problem because I have more other Java Selenium AutoIT tests that rely on using "MyProfile" with the plugin installed in that profile and not "Anonymousxxxxx.profile".
5) I cannot have it install into a new anonymous profile each time the test is run. I need it to install into 1 profile each time.
Has anyone came up with a solution to this problem?
This would seem to be a common web application type of test, surely someone was able to overcome this problem.
Here is the code I have already used in hopes of having webdriver use the proper profile. Unfortunately, it appears that it just grabs all the plugins and extensions from that profile and loads it into its own "anonymous" profile.
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("MyProfile");
driver = new FirefoxDriver(profile);