How to handle Windows Download dialog box using selenium web driver - selenium-webdriver

I am using selenium web driver (Not selenium RC). I need to download a xml file by clicking a link. I have did some Google search, and I have found in some answers an using AutoIT in order to handle OS related dialog boxes.
But is there any other option using selenium to handle this without using AutoIT tool.
Kindly suggest some ideas.

Can you be a bit more specific which browser you are using. If it's firefox you can have a greater control on the file download. Any other browser including firefox you can use robot class. This can be used to perform the click on ok button for downloads. If its chorme then file download happens automatically without any intervention.

For the newest version of Firefox (as of writing), these are the arguments that I needed to avoid the download box. Note that you need to specify a directory that you can write to as seen in the third statement:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "browser.download.folderList", 2 );
profile.setPreference( "browser.download.dir", <YOUR DOWNLOAD PATH> );
profile.setPreference( "plugin.disable_full_page_plugin_for_types", "application/pdf" );
profile.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/csv,text/csv,application/pdfss, application/excel" );
profile.setPreference( "browser.download.manager.showWhenStarting", false );
profile.setPreference( "pdfjs.disabled", true );
Note that the last line with pdfjs is required for the newer versions of Firefox, where it wasn't before. More info Here

I face Authentication Proxy pop-up issue in my project. So I tried below solution and it is working fine.
When we run Script from Selenium Web driver on Security Environment following Setup needs to be done to handle Authentication Proxy.
First you need to know below details,
network.proxy.autoconfig_url (Example: "http://example.com/abc.pac")
network.proxy.http (Example: abc-proxy.com)
network.proxy.http_port (Example: 8080)
private static WebDriver initFirefoxDriver(String appURL)
{
System.out.println("Launching Firefox browser..");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("network.proxy.type", 1);
firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://example.com/abc.pac");
firefoxProfile.setPreference("network.proxy.http", " abc-proxy.com");
firefoxProfile.setPreference("network.proxy.http_port", 8080);
WebDriver driver = new FirefoxDriver(firefoxProfile);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to(appURL);
//driver.get(appURL);
return driver;
}

Related

Open original google chrome with selenium in python

I want to open google chrome(which has saved my information like my username and passwords) instead of Chromedriver.exe .
I tried some ways like opening chrome profile via:
from selenium.webdriver.chrome.options import Options
options = Options()
# or ->options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir= C:\\Users\\me\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
#or-> options.add_argument("--user-data-dir= C:\\Users\\me\\AppData\\Local\\Google\\Chrome\\User Data")
web=webdriver.Chrome( executable_path="c:\\Users\\me\\.spyder-py3\\chromedriver.exe" , chrome_options=options)
web.get('https://google.com')
and it didn't work.
also I tried web=webdriver.Chrome( 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe') and this way opened original chrome but didn't go to the link .
please tell me a way for using original google chrome instead of chromedriver.
Does this solve your problem: How to use certain Chrome profile with selenium python?
The exact call and arguments are a bit specific. If not, pleade post selenium version you are using (4.x is quite bew)

Can't open Private window in Edge Browser using Selenium

I have tried below mentioned code, but its not working in my framework.
Selenium -3.141.59
Microsoft Edge- 81.0.416.72
EdgeOptions options = new EdgeOptions();
options.setCapability("inPrivate", true);
WebDriver driver = new EdgeDriver(options);
You could try to add argument inprivate to make Edge Chromium open in Private mode using Selenium WebDriver.
Please refer to the following steps:
Download the language binding of Selenium 4.00-alpha05 from here.
Download the matching version of Microsoft Edge Driver from this page.
Then, using the following code (it works well in C# and Java application):
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.addArguments("-inprivate");
WebDriver driver = new EdgeDriver(edgeOptions);

Firefox Webdriver fails with UnreachableBrowserException and blank Screen

I am running webdriver 2.53.1 against firefox 45.9.0ESR on Redhat Linux 6.6. FirefoxDriver object gets created successfully and firefox launches with blank page (about:blank) as expected. But when I do the 'get' to open the url, it fails with UnreachableBrowserException with underlying cause as org.apache.http.NoHttpResponseException: localhost:7055 failed to respond.
Preferences set for FirefoxProfile
app.update.auto = false
app.update.enabled = false
app.update.silent = false
media.gmp-provider.enabled = false
webdriver.log.file = webdriver_debug.log
webdriver.firefox.logfile = firefox_browser.log
My observations
Browser is running and is not killed
Browser has webdriver addon added.
By 'netstat' I see webdriver listening on port 7055
Though I configured to dump firefox and webdriver logs, nothing gets dumped.
What I tried so far
Handling the exception and retrying does not help
The firefox is a tar ball extract. I tried removing the folder and extracting again, but that did not help either.
Used navigate().to(url) instead of get(url) but result is same.
NOTE: The JRE 7 is used for running
Upgrading Selenium
We cannot upgrade the selenium or firefox as there are many other dependent layers to be upgraded for selenium/firefox to upgrade.
You need to update your jars files of selenium both server and client.
Download the latest jars from below link :-
http://www.seleniumhq.org/download/
You also need to update your gecko driver from below URL :-
https://github.com/mozilla/geckodriver/releases
Additionality update your firefox
Help -> About

How can i configure in Appium the URL of an application?

I have the url of an application, (not the .ipa file), how can i configure this url in appium? i don't have the path for that file. The application is coded by Angular JS.
If the problem is only The path, this is how i do it:
zip the app folder (testapp.app.zip)
put zip file in a folder (~/server/)
open a terminal and cd to folder (cd ~/server)
run command python -m SimpleHTTPServer 8000
Your application address is http://localhost:8000/testapp.app.zip.
This is done on the appium side, your test code can be anywhere. localhost is what appium see, so there is no problem if you run test from another system.
You can do it via your code,
capa = new DesiredCapabilities();
capa.setCapability("app", "http://example.com/appname.ipa");
Providing the URL shouldn't have any credentials.
If its for safari use the below capabilities in the code not Appium gui
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.IOS);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"7.1");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"safari");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"iPhone Simulator");
IOSDriver driver=new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://google.com");
Thread.sleep(4000);
driver.quit();
I have solved my problem by 2 ways :
I put in URL the path for * > /Debug-iphonesimulator/UICatalog.app
Adding app : "safari" and i run appium with npm version 1.5.5 like
that :
appium --default-capabilities
'{"app":"safari","browserName":"safari","appium-version":"1.5.1","platformName":"iOS","platformVersion":"9.3","deviceName":"iPad Air","nativeInstrumentsLib":true}' --command-timeout "0"
--pre-launch
--nodeconfig "/Users/me/nodeconfig.json" --launch-timeout "180000"

How to open safari browser using Selenium WebDriver?

Can anyone please explain me the below doubt?
How to open google page in safari browser using Selenium WebDriver?
I am using the below code to open the safari browser.
WebDriver driver = new SafariDriver();
driver.get("http://www.google.com/");
But I am getting "SafariDriver requesting connection at ws://localhost:40921" error message
Can anyone please help me for the above?
You need to install Safari Extensions Developer Certificate in your machine and also install selenium webdriver as an extension in Safari Browser.
Also there are some stability issues with Safari browser & Selenium combination on Mac 10.9 OS and below.
The stability is much better on Mac Yosemite OSX & Safari 8.0.x combination along with Selenium v2.45.0
Have you checked out these links?
http://code.google.com/p/selenium/wiki/SafariDriver
http://code.google.com/p/selenium/issues/detail?id=3827
Prerequisite: Install Safari on Windows if it is not already installed
Go to http://docs.seleniumhq.org/download/
Scroll down -> Go to the section "SafariDriver" and download "SafariDriver.safariextz"
Double click on "SafariDriver.safariextz" (previously downloaded)
Safari would open with a pop up containing "Install" button -> Click Install button
Now go to Preferences of Safari -> Extensions tab : you would see WebDriver (in my case WebDriver 2.48.0) is installed (Enable WebDriver checkbox is checked))
It's now time to instantiate SafariDriver and get the desired URL by using Java. Please find the code:
WebDriver driver = new SafariDriver();<br>
driver.get("https://www.lynda.com/Ripon-Al-Wasim/8496323-1.html");
First of all, you don't need to download safaridriver if you having MacOS High Sierra and later, as its already present by default at
cd /usr/bin
ls -a
Can check here safaridriver is already present
so how to configure this safaridriver in test files
private static final String KEY_SAFARI_WEBDRIVER = "webdriver.safari.driver";
private static final String SAFARI_WEBDRIVER_PATH = "/usr/bin/safaridriver";
System.setProperty(KEY_SAFARI_WEBDRIVER, SAFARI_WEBDRIVER_PATH);
WebDriver driver=new SafariDriver();
By default automation testing option is disabled in safari,
can enable it from safari browser
Develop -> Allow remote automation
reference: https://www.lambdatest.com/blog/selenium-safaridriver-macos/
Try this instead:
System.setProperty("webdriver.safari.driver","C:/safaridriver.exe")
WebDriver driver = new SafariDriver();

Resources