How to disable 'Download Complete' notification using selenium Webdriver - selenium

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.

Related

How to inspect elements IE settings options -Selenium

I need to launch IE browser and click on IE settings option and do some action. I launched IE browser but not able to click on Settings as inspect element is only restricted to webelements but not to IE settings tools.
Does anyone know solution for this?
You can try pressing (ALt+X) command using any Robot or Action Class once you lauch your browser. It will open setting tab.
I try to search but did not get any way to access IE options and settings using Selenium.
If we talk from a browser side, Than browser will also not allow any automation to access settings.
Someone can miss use it and try to change browser settings without informing the user. Than it can be a security related issue.
Although, It is not possible to access browser setting panel.
But We can achieve some scenario using desired capability:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
//Examples
capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability("allow-blocked-content", true);
capabilities.setCapability("allowBlockedContent", true);
capabilities.setCapability("ignoreZoomSetting", true);
capabilities.setCapability("ignoreProtectedModeSettings", true);
capabilities.setCapability("requireWindowFocus", true);
capabilities.setCapability("enablePersistentHover", false);
capabilities.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());
System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe");
//it is used to initialize the IE driver
WebDriver driver = new InternetExplorerDriver(capabilities);
Note: Please provide exact details what you want to achieve.
As per your requirement >> add new entry to add site to apps option in tools
************ Solution ***********
Robot robot = new Robot();
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_X);
for (int i = 1; i <= 5; i++) {
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
}
robot.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(1000);
robot.keyRelease(KeyEvent.VK_ESCAPE);
Note: Above code will do, if not please handle according to your requirement.

Why with FirefoxProfile script window.open() open new window instead tab?

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.

Naurki.com has two new ad popups when the url is launched. How to handle this? Can enabling popup blocker in chrome via Chromeoptions will work?

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.

How to automatically close firebug tab when launching selenium firefox webdriver with firebug?

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);

Selenium- Popup got blocked if I clicked Link using Javascript Executor in Chrome browser

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);