I have multiple products on the Screen, each of them differs from the string "ProductName". Instead of collecting all the products onto the page. I want to make any dynamic or reusable function so that I can pass the product name on the function and it should recognize the element
public findElement(String ProductName)
{
element= By.xpath("//a[contains(text(),'ProductName')]");
}
If I pass the product name to Apple, then it should give me the locator as
element= By.xpath("//a[contains(text(),'apple')]");