Using firefox and Chrome Driver in selenium 2.24.0 - firefox

I'm using Selenium to buid a project about automation testing but I have some problem with these lines of code :
String exePath = "Browser\\firefox5.0.1\\firefox.exe";
var firefoxProfile = new FirefoxProfile();
m_browser = new FirefoxDriver(new FirefoxBinary(exePath), firefoxProfile);
m_browser.Navigate().GoToUrl(url);
I can't set firefox url with these codes. But if I use InternetExplorer instead, I can set IE url. I don't know where the problem is
Plz help me. Thank you so much!

If you want to use the chrome driver , you will have to set a property as follows -
System.setProperty("webdriver.chrome.driver","chrome driver path");
You can download the chromedriver.exe for your OS from the following location - http://code.google.com/p/chromedriver/downloads/list
To set up the firefox driver, the Firefox binary is assumed to be in the default location for your particular operating system such as for windows - %PROGRAMFILES%\Mozilla Firefox\firefox.exe (reference - http://code.google.com/p/selenium/wiki/FirefoxDriver)
If firefox is in it's default location you don't have to specify the firefox binary path. But if want to do that, check out this link - FirefoxBinary(java.io.File pathToFirefoxBinary) to make sure your constructors are correct.

Related

How to make the settings for Download in Firefox when launched using Webdriver?

I have set this option in my Firefox for Downloads. But each time I am opening the Firefox using Webdriver it is set to Save files to Downloads. So whenever there is a file which is to be downloaded from Firefox launched by Webdriver, it will save to default location.
What can I do so that it always asks me for Download location when launched using webdriver?
Create a firefox profile like this:
https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
In this profile, set the correct download destination.Now in your code when you create the firefox driver, start it with the newly created profile. This should do the trick.
I was able to achieve this using the following code snippet:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.download.useDownloadDir", false);
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://www.google.com");

Unable to determine the current version of FireFox after updated to 28.0

When I run my Selenium tests with Firefox 28.0 I get:
"An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to determine the current version of FireFox using the registry, please make sure you have installed FireFox correctly"
I successfully ran tests yesterday with Firefox.
I think Firefox auto-updated to 28.0 since yesterday.
Today I'm getting the above error.
I uninstall Firefox and reinstalled but I still get the same exception.
Selenium 2.40
Firefox 28.0
Gallio and MbUnit 3.4
Any ideas on how to fix? I suppose I could switch to IE for testing.
Ed
The error was generated on the call to FireFoxBinary() constructor.
DriverObj = New FirefoxDriver(New FirefoxBinary(), New FirefoxProfile(), TimeSpan.FromMinutes(10))
The call to FirefoxBinary worked for three weeks so I'm not sure why it decided to fail yesterday. Perhaps it was the auto-update by Firefox from 27 to 28.
The solution was to add the file path to the Firefox binary:
DriverObj = New FirefoxDriver(New FirefoxBinary("C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"), New FirefoxProfile(), TimeSpan.FromMinutes(10))
One possible solution to this would be to manually add the registry key that is being searched for. Normal FireFox builds (non ESR) appear to place a key titled "CurrentVersion" with a string value of the version in the
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla FireFox
directory. Testing has shown me that when I place a key similar to this but with a string value of the ESR version installed on my system in this location Selenium will work. The caveat is that as this question is rather old I have tested with Selenium 3.0.1. If you would like to try this the your registry key should look like this without the quotes:
Name = "CurrentVersion" and
Value = "45.6.0 ESR (x86 en-US)"
Please keep in mind that this solution will get you by in a pinch, but each time ESR updates you will need to go in and update the key value.
This was driving me mad, until i finally cracked it, here's the code that fixed mine:
var options = new FirefoxOptions();
options.BrowserExecutableLocation = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
IWebDriver driver = new FirefoxDriver(options);

Downloading PDF's with Webdriver

I am trying to download pdfs with selenium webdriver with python bindings on OS X 10.8.
I actually need the pdf file, not just check if it the download link works. As I understand it, I need to set the firefox profile to download the pdf content type, rather than 'preview' which is the default.
My code to open an instance of firefox is:
def Engage():
print "Start Up FIREFOX"
## Create a new instance of the Firefox driver
profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.dir', os.path.expanduser("~/Documents/PYTHON/Download_Files/tmp/"))
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/pdf'))
driver = webdriver.Firefox(firefox_profile=profile)
return driver
I have also tried initially setting the profile as :
profile = webdriver.FirefoxProfile()
## replacing :: profile = webdriver.firefox.firefox_profile.FirefoxProfile()
## the other attributes remained
This has the same results
This profile opens the pdf in preview mode in a new window, rather than download it.
I double checked the content type through requests and was able to confirm it as "application/pdf":
import requests
print requests.head('mywebsite.com').headers['content-type']
Any idea of what I am doing wrong?
Was facing a similar situation sometime back. Solution is quite easy. By default the settings in firefox opens pdf files rather than allowing you to download it. To overcome this type config:about in the browser and type pdfjs.disabled double click on the option. The value should change from false to true. Restart the browser and try opening any pdf file. It will download the file instead of opening it in the browser. Happy coding.
I was faced with the same problem. My code is in Java, but I'm sure you can transfer the properties to match in python. Here is what worked or me (note you need to specify a path to a directory that you can write to):
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 );

WebDriver / stuck when open upload file window

I use my WebDriver, with FireFox.
I have an elemnt: //input[#class="uploadFiles"], when I click on it by:
driver.findElement(By.xpath("//input[#class="uploadFiles"]")), a windows of upload a file (Windows OS's window) is opened, but the test doesn't continue to the next line, and get stuck.
Any help?
Webdriver doesnt interact with os level dialogs and that's the reason it doesnt continue to the next line. Here's something to help you : http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_Does_WebDriver_support_file_uploads?
No you cant do it with WebDriver as niharika_neo answer but you can do next:
string filepath = "my local path";
_driver.FindElement(By.Id("attachments")).SendKeys(filepath);
_driver.FindElement(By.Id("attachments")).SendKeys(Keys.Return);
You can't interact with OS level Windows directly. You can go through the path given by niharika_neo or else you can use Auto IT tool for handling the OS level windows. The best option is to use Auto IT tool.
I faced the same problem with FF, then I found that it was specific to the FF version I am using. I installed and ran the tests on FF 11, and I was able to successfully runt he tests. Try changing the version of FF that you are using.

Webdriver and firefox changes http://localhost/ to http://localhost.com/ - why?

I'm running the following on Win7 with Java6 and Firefox with webdriver:
WebDriver driver = new FirefoxDriver();
driver.get("http://locahost/");
Instead of opening my local server this opens http://www.localhost.com/ which is a registered domain on the internet.
Why is webdriver doing this?
How can I fix this in a way that doesn't involve changing my hosts file?
There is no server at locahost:80 (because of the typo?). If a host name has been entered into the location bar and doesn't resolve then Firefox will try to "fix it". This behavior is controlled by the preferences browser.fixup.alternate.enabled (by default true), browser.fixup.alternate.prefix (by default www.) and browser.fixup.alternate.suffix (by default .com). Webdriver allows changing Firefox preferences via FirefoxProfile.setPreference() so you can disable this behavior - or simply fix the typo.

Resources