driver.switch_to.window('WEBVIEW')
driver.switchTo().window("WEBVIEW");
If multiple web views are displayed, the command get window handles is then returning the names of the different web views.
Based on a sample html (Source ), the locators can be used in the following way:
<html>
<head><title>sample page</title></head>
<body class="logged_out env-production">
<div id="main">
<div id="header" class="true">
...
<div class="topsearch">
<ul class="nav logged_out">
<li class="pricing">
<a href="https://github.com/plans">Signup and Pricing</a>
</li>
<li class="explore">
<a href="https://github.com/explore">Explore GitHub</a>
</li>
<li class="features">
<a href="https://github.com/features">Features</a>
</li>
<li class="blog">
<a href="https://github.com/blog">Blog</a>
</li>
<li class="login">
<a href="https://github.com/login">Login</a>
</li>
</ul>
</div>
...
</div>
...
</div>
...
</body>
</html>
Means the id of an element that is described in the html source of the web page.
driver.find_element(:id,'header')
driver.findElement(By.id("header"));
Is mapped to the name of the view element.
driver.find_element(:name,'name')
driver.findElement(By.name("name"));
Mapped to the displayed text of the element.
driver.find_element(:link_text,'Blog')
driver.findElement(By.linkText("Blog"));
Mapped to the displayed text of the element.
driver.find_element(:partial_link_text,'Blo')
driver.findElement(By.partialLinkText("Blo"));
Mapped to the ui element class of the view.
driver.find_element(:class_name,'login')
driver.findElement(By.className("login"));
Mapped to the name of the ui element tag e.g.: a.
driver.find_element(:tag_name,'a')
driver.findElement(By.tagName("a"));
XPath is the language used for locating nodes in an XML document. XPath extends beyond (as well as supporting) the simple methods of locating by id or name attributes, and opens up all sorts of new possibilities such as locating the third Button on the activity.
driver.find_element(:xpath,'//a[@title='logo']')
driver.findElement(By.xpath("//a[@title='logo']"));
driver.find_element(:css,'ul.nav li')
driver.findElement(By.cssSelector("ul.nav li"));