CHAPTER 9

image

Navigation and Browser

Driving common web controls were covered in Chapters 2 through 8. In this chapter, I show how to manage browser windows and page navigation in them.

Go to a URL

driver.Navigate().GoToUrl("https://google.com");

Alternatively, set the driver.Url property.

driver.Url = "http://testwisely.com";

Visit pages within a site

driver.Navigate().GoToUrl() takes a full URL. Most of time, testers test against a single site and specifying a full URL (e.g., http://...) is not necessary. We can create a reusable function to simplify its usage.

String siteRootUrl = "http://test.testwisely.com";// ...public void Visit(String path) ...

Get Selenium WebDriver Recipes in C#, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.