ByChained Locator

With this locator, DOM traversal becomes extremely simple. ByChained traverses from the first locator in the variable argument list and continues until the last element locator in the list. 

We have introduced one more test textbox, which is inside a span, and the span is inside a div. Let's see the final structure of the HTML document.

The following HTML code shows the structure of the sample page:

<html>
<body>
<p>
First Name:
<input type=text id=fid/>

</p>
<p>
Last Name:
<input type=text name=lname/>
</p>
<p>
Address:
<input type=textarea class="tarea" id="tid" name="tname"/>
</p>
<div class="div1">
<span id="spn1">
Test:
<input type=text name=testname/>
</span>
</div>
</body>
</html>

The following code walks through a chain of locators starting from the parent div, taking the span next, right into the final test textbox:

public class ByChainedDemo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")
+ "\src\main\resources\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("C:\Users\Bhagyashree\Desktop\Documents\myHTML.html");
driver.findElement(
new ByChained(By.className("div1"), By.id("spn1"), By
.name("testname"))).sendKeys("FirstTest");
}
}

With this, we complete the three additional locator mechanisms.

We have explored Selenium 3 throughout this book. It's time to see what Selenium has in store for us in the future.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.208