Selenium: Change By-instance or concat two By-instances Selenium: Change By-instance or concat two By-instances selenium selenium

Selenium: Change By-instance or concat two By-instances


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:

  1. You can do something like:

    WebElement parentEl = driver.findElement(By.xpath(""))WebElement childEl = parentEl.findElement(By.className(""))
  2. Use the PageFactory @FindBys. See Selenium PageFactory and Selenium API.