Blank firefox page launched from selenium - c#

I am a new selenium user trying to launch Firefox from C# with selenium version 2.33.0
and Firefox version 20
Here is my code to launch firefox
var capability = DesiredCapabilities.Firefox();
Driver = new RemoteWebDriver(new Uri(Environment.SeleniumGridHubUrl), capability);
Here is my code to goto Url
Driver.Navigate().GoToUrl(Environment.Hostname[domain] + pathAndQuery);
The Firefox browser is launched successfully, however it is blank and does not display the webpage.
What I am missing here?

In your case if the gotourl is blank then you would get blank page.
This is what I usually do:
IWebDriver driver;
driver = new FirefoxDriver();
String baseURL = "http://localhost";
driver.Navigate().GoToUrl(baseURL + "/somepage.aspx");

This can happen with non compatible versions of Firefox. Make sure you turn off auto-update in the Firefox settings to avoid the latest version being installed by default.
To test that it is Firefox at fault change your WebDriver to another driver such as InternetExplorerDriver, ChromeDriver or SafariDriver.
Until Web Driver is supported, you can always downgrade your version of Firefox. Hope this helps.

Related

org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary [duplicate]

For compatibility reasons I prefer to use Chrome version 55.0.2883.75 with Chromedriver v. 2.26. I downloaded the older version of chrome from https://www.slimjet.com/chrome/google-chrome-old-version.php and Chromedriver 2.26 from https://chromedriver.storage.googleapis.com/index.html?path=2.26/.
I am using the following code to attempt to set my Chrome binary location:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome('chromedriver.exe', chrome_options = options)
However, when I attempt to launch the WebDriver Python returns the following error:
WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.26.436362
(5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)
I have tried searching through similar questions and answers but have not had any luck so far. Any help is greatly appreciated - thank you in advance!
This error message...
WebDriverException: unknown error: cannot find Chrome binary
...implies that the ChromeDriver was unable to find the Chrome binary in the default location for your system.
As per the ChromeDriver - Requirements:
The server expects you to have Chrome installed in the default location for each system:
OS
Expected Location of Chrome
Linux
/usr/bin/google-chrome1
Mac
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP
%HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista and newer
C:\Users%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Using a Chrome executable in a non-standard location
However you can also override the default Chrome binary location as follows:
To use Chrome version 55.x installed in non standard location through ChromeDriver v2.26 you can use the following code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()
Related Docs
Reference
You can find a detailed discussion in:
Is Chrome installation needed or only chromedriver when using Selenium?
What happened to me is that I didn't have chrome, the main browser, installed.
Download the browser and it fixes this issue.
Using an old version of chrome driver with the latest Google Chrome locally gave me the same exception.
Just go to the ChromeDriver page and make sure you have the latest version.
I faced similar issue in MacOS. Even after setting binary path in chromeoptions, it didn't work. It got fixed after installing npm i chromedriver
It is also important to download Chrome from the actual website. I ran into the same problem, but I had downloaded Chrome from the Ubuntu software package manager. I uninstalled the package manager version and installed from the website, and the error resolved. Same issue could probably arise installing from other package managers.
Check https://sites.google.com/a/chromium.org/chromedriver/getting-started
You can specify the binary path in the constructor of the webdriver:
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
I did this to solve my problem
private WebDriver driver;
#Before
public void StartBrowser() {
System.setProperty("webdriver.chrome.driver", "C://opt//WebDriver//bin//chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");}
I have solved this problem by installing Google Chrome link and it solved problem automatically (I use Kali Linux) and be sure that it is installed to the "/usr/bin"(default it is downloaded to here).

Edge launches but fails to navigate to uri

I am using selenium remotedriver(with C#) for chrome and edge. The tests seem to run fine on the chrome browser but not on edge. Edge is launched but fails to navigate to the specified uri.
I tried to make sure, I have the same version of webdriver as the installed version of edge, I am on windows 10 so it is already turned on.
var options = new EdgeOptions();
options.PageLoadStrategy = PageLoadStrategy.Eager;
_driver = new EdgeDriver(driverPath,options);
_driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
_driver.Navigate().GoToUrl("www.google.com");
The image contains the nuget packages added to the project
Microsoft Edge 44.18362.329.0 that is installed. Any help would be deeply appreciated.
I tried to test the issue on my side with Microsoft Edge 44.18362.1.0, Windows 10, Selenium web driver version V3.141.0
Tested code:
class Program
{
private static StringBuilder verificationErrors;
[Obsolete]
static void Main(string[] args)
{
var options = new EdgeOptions();
options.PageLoadStrategy = PageLoadStrategy.Eager;
IWebDriver driver = new EdgeDriver(options);
driver.Navigate().GoToUrl("www.google.com");
}
}
Code is working fine on my side and opening the web page without any issue.
Output:
I can see various entries for Web drivers in your package manager.
I suggest you to just installed the Selenium web driver v3.141.0 in new separate project and try to run this code in it to check whether it helps solve the issue or not.
If it solves the issue than remove unnecessary entries from your project may help to solve your issue.

Geckodriver with selenium 3.0 throws DriverServiceNotFoundException

I need help to upgrade to geckodriver using C#. I downloaded geckodriver from here. Downloaded windows 64bit version as I'm on windows 10 64bit. Copied the driver to my project location.
Environment.SetEnvironmentVariable("webdriver.gecko.driver", #"C:\Git\AutomationTest\Drivers\geckodriver.exe");
FirefoxDriverService driverService = FirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
driver = new FirefoxDriver(driverService, new FirefoxOptions(), TimeSpan.FromMilliseconds(600));
It threw error:
Initialization method UnitTestProject1.UnitTest1.Init threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases..
Result StackTrace:
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
at OpenQA.Selenium.Firefox.FirefoxDriverService.CreateDefaultService()
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor()
at UnitTestProject1.UnitTest1.Init()
Tried renaming it to 'Wires' but didn't work. Searched so many questions on SO, didn't find a solution with Selenium 3.0.
Added the path of the folder that has the driver to System variables path and tried using DesiredCapabilities.
DesiredCapabilities cap = DesiredCapabilities.Firefox();
cap.SetCapability("marionette", true);
var driver = new RemoteWebDriver(cap);
Using Selenium 3.0, FF 47.0.1, gecko v0.11.1
Can someone help me with this issue.
Thanks.
Try this:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("C:\Git\AutomationTest\Drivers");
IWebDriver driver = new FirefoxDriver(service);
I updated Firefox to Version 49.0.2 and updated my selenium driver to 3.0.0 from nuget packages. Added Firefox path to the system path variables. That's it I didn't change anything else in my coding i.e, declaration of Firefox. After updating I'm having too many issues like wait and System.Net.Web exception. I need to fix some of my test cases but it works.

Browser extension testing with selenium c# in Saucelabs

Is it possible to test browser extensions with selenium c# in Saucelab. If so how and where to place the latest extension package in saucelab VM so that selenium launches the browser with the extension.
For Firefox and chrome it is possible by providing capabilities or profile. For Example in case of firefox:
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);

WebDriver Firefox driver doesn't work

I'm using selenium webdriver 2.42.0, Firefox 29, C# and trying to create firefox driver
FirefoxProfile fp = new FirefoxProfile();
driver = new FirefoxDriver(new FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"), fp);
I see a new Firefox window and get WebDriverException
Failed to start up socket within 45000 ms. Attempted to connect to the following addresses: 127.0.0.1:7055
Everything works fine with ChromeDriver and IE driver. The only advise I found is to check FF and selenium versions, but as I know FF29 and webdriver 2.42 should work together.
I'm also tried to use FF27, 28, 30, nothing works.
Upgrade your selenium to newer version. If you use Maven Visit https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java

Categories