I had a very strange issue: for the open new tab(not a window) in Firefox thougth Selenium I use:
((JavascriptExecutor) driver).executeScript("window.open()");
And this worked ok, but when I added FirefoxProfile for FirefoxOptions like this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("media.peerconnection.enabled", false);
options.setProfile(profile);
And instead of new Tab in the same window .executeScript("window.open()"); open all in new window. But I need both things new tab for window.open() script and set media.peerconnection.enabled to false.
How can this happen why JS behavior depending on the profile?
How can I fix this?
I mean set media.peerconnection.enabled without a profile or prevent change JS behavior with Profile.
Related
I am using the below code to enable popup blocker. But this doesn't work.
Map<String, Object> prefs= new HashMap<String,Object>();
prefs.put("profile.default_content_setting_values.popups", 2);
ChromeOptions coptions= new ChromeOptions();
coptions.setExperimentalOption("prefs", prefs);
driver= new ChromeDriver(coptions);
I found a simple walkaround for this problem. We can find the window popups via WindowHandles and using a loop, we can switch to that window, close it and return back to the parent window. This also helps when the number of popup ads is varying.
#Test
public void captchImage() throws IOException
{
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
WebDriver driver = new FirefoxDriver(firefoxProfile);
driver.get("http://njdg.ecourts.gov.in/njdg_public/index.php");
I want to open firefox browser along with plugini attached image please go through that
You don't need to launch your plugin like this, rather use ProfileIni to launch the profile required.
Profile management in Selenium
Store your extension in a profile and then get that profile name and launch it in your browser.
Launching specific profile.
ProfileIni pro=new ProfileIni();
org.openqa.selenium.firefox.FirefoxProfile profile=pro.getProfile("ProfileName");
WebDriver driver=new FirefoxDriver(profile)
I have included firebug when launching firefox driver and it works very fine with latest selenium web driver 3.0 but meanwhile it also opens new firebug tab every time when launching browser.
As code says, i have included firebug file and added this extension in created profile. Is there any way to close the firebug tab automatically after launching the browser? If there is no automatic way then i need to use tweak to close window named "Firebug" right?
Code:
File file = new File("./firebug-2.0.17-fx.xpi");
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("marionette", true);
webDriver = new FirefoxDriver(capabilities);
You can set the "showFirstRunPage" flag to "false" in your porfile.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.showFirstRunPage", false);
Here is a link to all firebug preferences you can set.
Firebug Preferences
An other solution is to set the "currentVersion" to a big number like this.
profile.setPreference("extensions.firebug.currentVersion", "999");
I prefer the first on ;)
I was looking for automatically closing Firebug window but i think its not possible so posting an answer to handle opened windows after launching firebox browser with firebug capabilities, unfortunately you need to deal with extra lines of code due to this issue :)
Below solution it works fine, just use it like below:
Working code:
File file = new File("./firebug-2.0.17-fx.xpi");
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("marionette", true);
webDriver = new FirefoxDriver(capabilities);
// Close the firebug window
Thread.sleep(4000); // Firebug window takes time to open it
Set <String> windows = webDriver.getWindowHandles();
String mainwindow = webDriver.getWindowHandle();
for (String handle: windows) {
webDriver.switchTo().window(handle);
if (!handle.equals(mainwindow)) {
webDriver.close();
}
}
webDriver.switchTo().window(mainwindow);
I am using selenium to automate a functionality on my webpage.
I am downloading certain files using selenium. But as soon as a download completes, I can see a pop up notification on my web page that the download is complete.
enter image description here
Kindly suggest using selenium, I can I remove this pop up notification?
I am setting the following firefox profile:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.manager.useWindow", false);
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
firefoxProfile.setPreference("browser.download.manager.closeWhenDone", true);
firefoxProfile.setPreference("browser.download.dir", downlodeLocation);
firefoxProfile.setPreference("browser.helperApps.neverAsk.openFile",
"application/bin,application/binary,text/comma-separated-values,application/octet-stream,text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,text/html,text/plain,application/csv,text/anytext");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/bin,application/binary,text/comma-separated-values,application/octet-stream,text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,text/html,text/plain,application/csv,text/anytext");
Any help will be appreciable.
Thanks
You can do it via the browser settings
Type about:config in the address bar. Search for browser.download.animateNotifications or browser.download.manager.showAlertOnComplete and set them to false by right click -> toggle.
Problem Description - Upon clicking a link on the page, popup got blocked automatically.
file = new File("tools/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
caps.setCapability("ignoreZoomSetting", true);
caps.setCapability("nativeEvents", false);
driver = new ChromeDriver(caps);
Environment used – Selenium WebDriver – 2.43.0 ChromeDriver, Windows 7
Note – it is working fine on Firefox & IE, this issue is happening on Chrome only.
Please assist on this.
This is a Chrome Option to disable all popups for the site
Open Chrome.
Find a page that has pop-ups blocked for you.
At the end of the address bar, click the pop-up blocker icon chrome op-up
locked.
Click the link for the pop-up window you'd like to see.
To always see pop-ups for the site, select Always show pop-ups from [site].
Once you have this set use the profile it is saved against to load for the test
Another option is to open the site and Shift F5 to do a Cache Refresh
Load a Profile. The code below is C# and you haven't specified a language. Please see the links provided for Java examples
ChromeOptions options = new ChromeOptions();
userDataPath = "C:/Users/user_name/AppData/Local/Google/Chrome/User Data";
options.AddArguments("user-data-dir=" + userDataPath);
options.AddArguments("--start-maximized");
driver = new ChromeDriver("pathToChromeDriver", options);
You can pass the chromeOption to allow pop-up as shown in below:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.popups", 1);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);