3. Navigating
The first thing you’ll want to do with WebDriver is navigate to a link. The normal way to do this is by calling get
method:
driver.get("http://www.google.com")
WebDriver will wait until the page has fully loaded (that is, the onload
event has fired) before returning control to your test or script. Be aware that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use waits.
3.1. Interacting with the page
Just being able to go to places isn’t terribly useful. What we’d really like to do is to interact with the pages, or, more specifically, the HTML elements within a page. First of all, we need to find one. WebDriver offers a number of ways to find elements. For example, given an element defined as:
<input type="text" name="passwd" id="passwd-id" />
you could find it using any of:
element = driver.find_element_by_id("passwd-id") element = driver.find_element_by_name("passwd") element = driver.find_element_by_xpath("//input[@id='passwd-id']") element = driver.find_element_by_css_selector("input#passwd-id")