Meghasri
Meghasri

Reputation: 105

Concatenating variable for the ID value in xpath-selenium Webdriver

My xpath is //[@id='u2001'] It contains value 2001, but i dont want to use direct xpath instead i want to make the value 2001 alone as my input into the xpath, say for example something like .//[@id='ucurrentYearminus15'] here currentYearminus15 is my variable declared

Can someone help me how can insert my variable declared in the ID value? I want to know the syntax of it

Upvotes: 1

Views: 6992

Answers (1)

Chandra Shekhar
Chandra Shekhar

Reputation: 664

Your need is only Java coding. Declare 'currentYearminus15' as a String variable.

String s = "currentYearminus15";

Give your Xpath as driver.findElement(By.xpath("//[@id='u"+s+"']"));

Upvotes: 3

Related Questions