I want to use the argument 'option' as part of the findElement by the Xpath Expression:
public HomePage clickSizeOption (String option){
driver.findElement(By.xpath("span[contains(@class, 'checkmark') and text()= option]")).click();
return this;
}
But java treats the entire by xpath as a string.
HTML Context:
CodePudding user response:
You should be able to use the format() method for this. I also noticed your xpath doesn't start with '//'.
Afaik an xpath should always start with '//' except if you start from the html element.
Try this out
driver.findElement(By.xpath(String.format("//span[contains(@class, 'checkmark') and text()= %s]", option)).click();