How to Append the Value in XPath
It’s a common question that “How to add/append the value in XPath?“. Here is the right solution of it.
For Example you have the
Xpath = "//div/1234[td])"
Now , Scenario is that you just want to change the 1234 in the XPath. Then you can do it simply in this way.
First Create a String and assign it any value
final String MyValue = "6789";
Now, Add any XPath in which you want to append the value and pass the MyValue in XPath in this way by using concatenation.
@FindBy(how = How.XPATH, using = "(//div/"+ MyValue +"[td])")
Create a private WebElemnet and Name it as you want.
private WebElement NewXpath;
Finally, it will look like this below:
final String value = "12345"; @FindBy(how = How.XPATH, using = "(//div/"+ MyValue +"[td])") private WebElement NewXpath;
You can see the question related to it here on stackoverflow
For more blogs, click here
Leave a comment