Is it possible to combine/concat two Bys?
If I have one By
By parentBy = new By.xpath(".//div[@class='parent']")
and another By
By childBy = new By.xpath(".//div[@class='child']")
is it possible to concat the two Bys to a new one that has this xpath?
By combinedBy = new By.xpath(".//div[@class='parent']/div[@class='child']")
Something like
By combinedBy1 = parentBy + childBy
By combinedBy2 = parentBy.Concat(childBy)
Usecase:
We use the page object model.
Now I have a table as kind of child page object model. This table should have a method to select some data. Because of some html-structure issues (it is third party) I have to xpath a cell of the table that is child of a div (the row) by checking for a class of the cell and the text/content of this cell.
In addition to what @SiKing said, I would also recommend looking at the ByChained
class (see here for javadocs).
Example on how to use it:
driver.findElements(new ByChained(By.id("product-table"), By.className("quantity")));
Not sure if this addresses OP's question directly, but still very useful.
You have two options:
You can do something like:
WebElement parentEl = driver.findElement(By.xpath(""))
WebElement childEl = parentEl.findElement(By.className(""))
Use the PageFactory @FindBys
. See Selenium PageFactory and Selenium API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With