Using selenium, not able to open Firefox with a saved profile - java

I have created a new Firefox profile, and want to call the profile in my selenium code to load Firefox using this profile (plugins, etc).
Given the code below.
System.setProperty("webdriver.gecko.driver","D:\\Software\\Firefox\\Driver\\geckodriver-v0.10.0-win64\\geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\Dev 8\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\j3yl2vj7.MyTest02"));
WebDriver driver = new FirefoxDriver(profile);
It opens Firefox with the default settings, instead of with my particular profile with the plugins etc.
Version information:
Selenium : selenium-java-3.0.0-beta2
Java : Java SE 1.7
Firefox : 45.0.2

According to this blog article, you need to run Selenium 3.0 with Java 8.

Related

FirefoxDriver do not launch any URL and perform any action

I have started a clear CentOS with Eclipse Neon, newest Selenium 3.7.1 and Firefox 52.4.
I'm trying to invoke any URL but Firefox starts and do nothing. I do not have any proxy.
I was trying to starts Firefox with default page like this:
FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("browser.startup.homepage", URL);
fp.setPreference("startup.homepage_welcome_url", URL);
fp.setPreference("startup.homepage_welcome_url.additional", URL);
it worked, but just page has been opened, nothing more.
It is common problem? How can i fix this?
You mentioned of using Selenium 3.7.1 and Firefox 52.4.
Release Notes of GeckoDriver clearly mentions that :
Note that with geckodriver 0.19.0 the following versions are recommended: - Firefox 55.0 (and greater) - Selenium 3.5 (and greater)
So as you are using, Selenium 3.7.1 you mustn't be using below geckodriver 0.19.0. Hence your solution would be to bump up your Firefox to v56.x level.

action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build() works on windows but doesn't work on linux

action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build() works fine on windows but doesn't work on linux. I am writing a testcase using selenium webdriver and I am trying to select all the text which is written in a rich textbox and have used this code snippet to perform the select all command.It works fine on windows on firefox 38 browser but when I run my testcases on jenkins machine which is a linux machine,browser is firefox(don't know the exact version but above version 33) this code snippet doesn't work.I have tried some alternatives like driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a")); and double click on rich textbox to select the text written in it but nothing works.What could be the reason,why these code snippets are not working on linux machine.
I have found the answer to my own question action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build() and driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));was not running on Linux machine Firefox browser because the native events were not enabled in my driver factory.To enable Native Events you need to write the following code in the driver factory i.e where the required driver is created
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
FirefoxDriver driver = new FirefoxDriver(profile);

ChromeDriver - Disable developer mode extensions pop up on Selenium WebDriver automation

I'm having the following issue:
When I'm running my automation tests, I keep getting the following alert "Disable Developer Mode Extension" in Chrome.
Is there a way to remove/disable this?. It is a blocker for me as it is making me fail some tests.
Thanks in advance
Did you try disabling the developer extensions with command line param?
Try with the following Selenium WebDriver java code:
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);
I cannot disable extensions because I'm developing & testing one.
What I'm doing to dismiss this popup is the following:
I load chrome with my extension using Selenium.
I then immediately create a new window (via the SendKeys(Control-N) method). This predictably brings up the "Disable Developer Mode Extensions" popup after 3 seconds in the new window.
I can't tell programmatically when it pops up (doesn't show in screenshots) so instead I simply wait 4 seconds.
Then I close the tab via driver.Close(); (which also closes this new window). Chrome takes that as "cancel", dismissing the popup, leaving the original window and tab.
I find this necessary because the popup interferes with normal selenium browser interaction, like SendKeys, which I'm using to switch tabs and windows.
As of Chromedriver v2.33, the correct way to avoid this message is to pass load-extension to the excludeSwitches argument of the chromeOptions object. The following Java code should do the trick, although I haven't tested it, as I am running Python:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Collections.singletonList("load-extension"));
As others have pointed out, the culprit is probably the Chrome Automation Extension, which is loaded automatically by Chromedriver when it launches Chrome.
Chromedriver v2.33 introduced the new switch to prevent the extensions from being loaded:
Updates to excludeSwitches capability that now allows to exclude --load-extension switch.
I suspect that this solution does not require you to disable all extensions. You should still be able to manually load others.
This has been automatically fixed with a combination of ChromeDriver.exe V2.23 + Chrome 53.0.
To understand which chrome version will work with which driver, we can use the following well detailed doc: https://sites.google.com/a/chromium.org/chromedriver/downloads
Enjoy Automated Testing!!
I worked around this issue by using AutoIT.
First, you'll need to create the script.
closechromewarning.au3:
WinWaitActive("[CLASS:Chrome_WidgetWin_1]")
Send("{ESC}")
The script needs to be compiled to a .exe, then place the .exe in the path so it can be run.
Function that closes the warning, using c# syntax:
public void CloseChromeDialog()
{
System.Threading.Thread.Sleep(5000);
Process.Start(#".\closechromewarning.exe");
}
Sleep(4000) did work, but I upped it to Sleep(5000) just to be sure.
Calling CloseChromeDialog():
if(browser == chrome) //pseudo code
CloseChromeDialog();
resolved in chrome 54 and chromedriver 2.25
I too faced this problem. The solution is, if you are using maven then just add:
-Dchrome.switches=--disable-extensions
It will disable all the extensions and you will not face this problem.
I am using selenium Webdriver 2.53 and chrome version 56.0.2924.87 and the chrome driver.exe which I am using is 2.27. with this combination it is working with the
System.setProperty("webdriver.chrome.driver", "./utilities/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
DesiredCapabilities caps = new DesiredCapabilities().chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);
Try to add setProperty above ChromeDriver instance
System.setProperty("webdriver.chrome.driver","C:/[PATH]/chromedriver.exe");
driver = new ChromeDriver(capabilities);
pywinauto works
import pywinauto
window_title = "Disable Developer Mode Extensions"
app = pywinauto.Application().connect(name_re=window_title)
win_ext = app.window(name=window_title)
win_ext.close()
This is because one of your extensions is running in developer mode. Go through your extension list and disable extensions one-by-one until you find the culprit(s).

How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)

How can I use Selenium with Java with a custom Firefox Profile?
Here is my configuration:
Firefox version: 12
Selenium version: 2.25
Language: Java
Platform: MacOS
Open Terminal
type: /Applications/Firefox.app/Contents/MacOS/firefox-bin -p ( change the path as necessary )
Create a new profile, save it in a directory as you wish..
Start firefox with this profile, add any add-ons, modifications as you wish.
In Selenium, use:
FirefoxBinary binary = new FirefoxBinary();
File firefoxProfileFolder = new File("/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile");
FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
profile.setAcceptUntrustedCertificates(true);
webDriver = new FirefoxDriver(binary, profile);
Again here change the absolute path as required.
Add add-ons like autoAuth to pass the HTML Authorization windows in Firefox to this profile..
For Windows, to create a new Firefox Profile, type:
firefox -profilemanager
in Run that will open the Firefox Profile Manager.
Let's say you have created a profile called Selenium, then you can use the following code:
ProfilesIni listProfiles = new ProfilesIni();
FirefoxProfile profile = listProfiles.getProfile("Selenium");
WebDriver driver = new FirefoxDriver(profile);
You cannot pass HTML authorization window with Selenium.
You have to use Auto IT for this purpose.
AutoIT gives you the platform to manage the windows based components.
You can invoke AUTO IT scripts from Selenium WebDriver

How do I run Firebug within Selenium WebDriver (Selenium 2)?

What's the best way to activate Firebug in Firefox when running Selenium 2?
Edit: Ok, I realize "best" is open to interpretation, but the profile-based solution really used to be a pain with selenium 1.0. So any alternative is considered better until proved worse ;)
You can create your profile in code and dynamically add required add-ons. Let's assume that you saved Firebug XPI into the C:\FF_Profile folder as firebug.xpi (go to Firebug download page, right-click on the "Add To Firefox" and save as C:\FF_Profile\firebug.xpi).
In code:
final String firebugPath = "C:\\FF_Profile\\firebug.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(firebugPath));
// Add more if needed
WebDriver driver = new FirefoxDriver(profile);
This is described in WebDriver FAQ
Do you mean having firebug installed in the browser instance that webdriver launches? If so, you can pass an extension when you instantiate the driver, but the eaisest way is to create a firefox profile with firebug installed and then use the following code before you instantiate the driver:
System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");
Just reference your profile by name. Example in Ruby:
#driver = Selenium::WebDriver.for :firefox, :profile => "default"
Then, load Firefox normally, and add your desired extensions. They will now show up in your Selenium test runs.
Apparently the way the firefox-profile options are consumed has changed in Selenium WebDriver.
The old commandline (Selenium RC):
java -jar selenium-2.28.0.jar -firefoxProfileTemplate ~/.mozilla/firefox/3knu5vz0.selenium
Updated for WebDriver: (note that it wants the profile name rather than the directory)
java -jar selenium-2.28.0.jar -Dwebdriver.firefox.profile=selenium
modify your firefox location to something like
C:\Users\user-name\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default
launch your firefox from selenium / webdriver
make all your required settings
close and restart firefox browser from selenium / webdriver
that's it, it solves your problem !!
I found a profiles.ini in ~/.mozialla/firefox/. In there was a profile named default, which I specified a like the following and then firefox was opened in test just like I opened it regularly (with all plugins etc).
java -jar selenium.jar -Dwebdriver.firefox.profile=default
If none of the above option works. Then try this.
1) Open terminal and type below command (close all existing firefox
sessions first)
firefox -p
2) This will open an option to create a new Firefox profile.
3) Create a profile lets say "SELENIUM".
4) Once the firefox is open straight away install firebug or any
other plugins extension that you want. once done close the window.
5) Now load this new profile via selenium , use below java
statements.
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
6) Done. Enjoy.
I have observed that the firebug is adding to browser and it is disabled by default and not enabled ,when i add firebug to firefox at runtime by using webdriver. So to make it enable we may need to add the below line to profile.
profile.setEnableNativeEvents(true);
Assuming that, Firebug is installed. Your objective is to run Firebug. Firebug can be run/execute by pressing F12 key. So Firebug can be run by following command of Selenium WebDriver with Java:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();

Categories