Select Page
Codoid Blog

Selenium ByChained Class

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

In this article, you are going to see an example of Selenium Webdriver ByChained class. Before jumping into the code, let’s understand what is ByChained class? ByChained class allows you to locate an element using its hierarchy in the DOM.

<html>
<body>
<div id="div1">
<div id="div2">
<input type="text" id="txt1"/>
</div>
</div>
</body>
</html>  

If you want to locate the textbox (txt1) from the above HTML using ByChained class, you need to pass ByChained object with By arguments in sequence. Note: You can also locate the element using XPath with DOM hierarchy.

ByChained Class Example:

driver.findElement(new ByChained(By.id("div2"),By.id("div1"),By.id("txt1"))).sendKeys("Codoid");  

Hope it helps!

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility