Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium IWebDriver Navigate().GoToUrl() not entering url or navigating to page

I'm creating a new test project and can't think of anything else to try to resolve my issue. I have another Selenium project that works as expected, and have compared the two to find differences. But first, the main issue I'm running into. In the setup I call Driver.Navigate().GoToUrl("www.test.com"); No exception is thrown or anything else that would indicate there is a problem, the flow just moves to the next statement, but no Url is entered into the navigation bar, and so obviously the driver never navigates to any page. The driver does start up a new firefox instance, but it stays blank.

When I compare this new project against an already working project, they seem identical for the most part. Both projects have ...\packages\Selenium.WebDriver.2.37.0 & ...\packages\Selenium.Support.2.37.0 installed using NuGet package manager. Both projects have identical references to the project in the .csproj file --Working project ... ....\packages\Selenium.WebDriver.2.37.0\lib\net40\WebDriver.dll False ....\packages\Selenium.Support.2.37.0\lib\net40\WebDriver.Support.dll

--Unworking project ... ..\packages\Selenium.WebDriver.2.37.0\lib\net40\WebDriver.dll ..\packages\Selenium.Support.2.37.0\lib\net40\WebDriver.Support.dll

Neither project does anything else. The constructor for both simply calls: var WebDriver = new FirefoxDriver();

When I examine the WebDriver object, the only difference I can see is the WindowsHandles property. The working project has: WindowsHandles Count = 1

The non-working project has: WindowsHandles {System.Collections.ObjectModel.ReadOnlyCollection}

I have no idea why they're different but as it's the only difference I can find, I'm thinking maybe that's the problem but I have no idea if that's really the case or how I'd fix it. I've added a try/catch block around the WebDriver.Navigate().GoToUrl() and no exception is being caught.
Both projects target the .NET 4.0 framework. Any help is greatly appropriated.

like image 307
Darian Everett Avatar asked Nov 26 '13 22:11

Darian Everett


People also ask

What is difference between get () and navigate () to () in selenium?

So the main difference between get() and navigate() is, both are performing the same task but with the use of navigate() you can move back() or forward() in your session's history. navigate() is faster than get() because navigate() does not wait for the page to load fully or completely.

Which command is used to navigate to a URL?

Google's Answer: get() is used to navigate particular URL(website) and wait till page load. driver. navigate() is used to navigate to particular URL and does not wait to page load.

Which method is used to browse the URL in WebDriver?

We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method. It fetches the URL of the opened application. This method accepts no parameters and strings the URL in the form of String.


2 Answers

I figured it out right after I finally broke down and decided to post on StackOverflow. My issue was IWebDrivers insists upon a passed in URL beginning with http. Once I prefixed my URL with that, it worked.

like image 136
Darian Everett Avatar answered Oct 22 '22 08:10

Darian Everett


Here is a simple example how to do so:

  1. Add NuGet package Selenium.WebDriver

  2. Download chromedriver (https://sites.google.com/a/chromium.org/chromedriver/) or any other driver from http://www.seleniumhq.org/download/ (section Third Party Browser Drivers NOT DEVELOPED by seleniumhq)

  3. Copy the file to your project directory in Visual Studio and set the following properties for the file:

    Build Action = None; Copy to Output Directory = Copy if newer

Once installed, try running the following example code:

var driver = new ChromeDriver();
var navigate = driver.Navigate();
navigate.GoToUrl("http://www.microsoft.com"); //works
navigate.GoToUrl("www.microsoft.com"); //does not work

Good luck!

like image 45
MZHm Avatar answered Oct 22 '22 10:10

MZHm