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);
Related
I am trying to run the org.openqa.selenium.firefox.FirefoxDriver in Java.
I would like to open a browser window without the address bar and other functionalities like page-forward and so on.
Actually I would like to have a plain window with the displayed web content and even disabled context menu.
How to archive that.
I tried with the code:
FirefoxOptions op = new FirefoxOptions()
.addPreference("browser.startup.page", 1)
.addPreference("browser.startup.homepage", "https://google.com");
WebDriver driver = new FirefoxDriver();
but could not find any good, easy understandable documentation for preferences or arguments (addArgument(...)).
Could anyone give me a hint here?
These resources also did not give me a good understandable help:
https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
https://searchfox.org/mozilla-central/source/modules/libpref/init/all.js
How to correctly use FirefoxOptions() and its arguments to pass it to the FirefoxDriver() constructor
Other threads I found on the internet are many years old.
As bonus, the same links for Chrome would also be appreciated.
This is a solution what I almost perfectly want. It does not deal with Selenium/Selenide, which is fully ok with me. I made it work nicely with Chrome browser.
See: https://github.com/greyshine/javaspring-embedded-browser
Most interesting files are the index.html and BrowserAdaptor.java.
What I still miss:
A nice way independent on the OS on how to locate the executable for the browser; see application.properties
Firefox does not open with a pure screen but still has tabs and some browser functions. What would be the startup parameters (see application.properties) for firefox to correctly start.
Same story for the Edge browser. Startup parameters, etc...
Bringing Selenide into the question was based, that I seen that this must be somehow possible.
One of the ways WebDriver identifies itself as a bot to external websites is by setting the webdriver-active flag to true.
A user on SO suggested that it is possible modify Chrome Driver source code to remove all bot-identifying attributes (see this and this response).
Is it possible to achieve a similar outcome w/ Firefox by modifying the source code of Geckodriver, Firefox WebDriver or perhaps both? I'm asking because there is currently no way to conceal WebDriver using Firefox Options without source code modification.
If we can somehow remove bot identifying features from the source code, we can prevent WebDriver from being identified as a bot without needing to bundle TOR with Firefox.
While there's no getting around the fact that Selenium (in its present state) identifies itself, surely we can modify source code to remove all identification similar to how it's achieved in Chrome Driver?
In the discussion Can a website detect when you are using Selenium with chromedriver? as suggested by different users to open the ChromeDriver in a Hex Editor and edit the document variables replacing the cdc_ and $wdc_ string might be possible, but achiving the same with GeckoDriver may not be possible.
Moreover, the commands like execute_cdp_cmd() and Python libraries like selenium-stealth may not be currently supported by GeckoDriver.
The GeckoDriver source code can be easily downloaded from mozilla / geckodriver page both in zip and tar.gz format. If you are on windows system you can unzip the downloaded file and find the the source code of different modules in the ...\geckodriver-0.30.0\src directory:
Additionally, geckodriver is made available under the Mozilla Public License. GeckoDriver source code can also be found in mozilla-central under testing/geckodriver.
WebDriver Specifications
Now as per WebDriver W3C Editor's Draft:
The webdriver-active flag is set to true when the user agent is under remote control. It is initially false.
So there can be two possible ways to keep webdriver flag as false as:
Remove the readonly attribute, so can be edited runtime. (as discussed in this answer)
Strangle the WebDriver from emitting the signals that the user agent is under remote control.
To me the second option looks pretty much viable as the most frequently updated tier is the second tier (Selenium WebDriver.dll and WebDriver.Support.dll modules). Since App Studio uses C# and .Net version 4.0 (before Selenium 4.1.0 (November 22, 2021)) to communicate with Selenium, you need to download the .Net 4.0 version of the Selenium modules. The current stable version being 4.1.0. Once the zip file is downloaded, extract the content to a folder and navigate to the net40 subfolder.
Now, you can copy the WebDriver.dll and WebDriver.Support.dll files to the bin folder of the App Studio installation. e.g, C:\ibi\AppStudio82\bin and make the required changes.
As an alternative, you can also download the NuGet, copy the .Net 4.0 content of the NuGet package into the bin folder of the App Studio installation and make the required changes.
tl; dr
Building geckodriver
Testing geckodriver
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.
The FileDownloader class provided on the question below worked fine until I upgraded to selenium 2.46:
Programmatically downloading a file using Selenium in Java
When I run the same test with selenium 2.46, I now get redirected to the login page. Did anyone else face this issue?
The Selenide project has a great, really well thought out, download helper in it. I would investigate that, either as an example, or possibly actually using it.
$.download()
I'm using Selenium Webdriver (Java) and PhantomJS to test a complex JS driven website. My problem is, that the PhantomJS browser keeps the session between two tests which leads to errors in the test setup.
If I run the tests with Firefox everything works fine because Firefox uses a clean session for every test case.
My first attempt to solve the problem was to just clear the local storage by JS injection. Cookies are deleted by the Selenium exposed API driver.manage().deleteAllCookies();
But executing JavaScript without visiting a page is not allowed. So starting the browser at "about:blank" leads to an error.
So, how do I configure my phantomjs webdriver to clear the session?
I'm using phantomjs and webdriver because the selenium-grid services turned out to be not stable enough. So I start my phantomjs instance like that:
phantomjs --webdriver=1234
The fact that PhantomJS keeps sessions between tests is a known problem in GhostDriver, the Selenium Webdriver implementation in PhantomJS.
I suppose that this problem will be fixed with the PhantomJS 2 release. The bug is already fixed in GhostDriver 1.1.1, but there is no PhantomJS version which includes this GhostDriver version.
I know that Selenium Grid has a "cleanSession" option if you use GhostDriver. Also, I am pretty sure the regular WebDriver class has a option for this on a local WebDriver instance:
driver.manage().deleteAllCookies();
The version 2.0 of PhantomJS fix this issue. If you have a Linux Enviroment, you need clone the sources and compile, like this:
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0
./build.sh
More info here