How to put parameter into xpath string (Java)

When you have i situation about your xpath strings like below:

".//*[@id='bankList']/p[.='ANZ']"
".//*[@id='bankList']/p[.='HSBC']"
".//*[@id='bankList']/p[.='Barclays']"

 

The best way to use 1 xpath string do define all of them, Java has method to support it:

String bank = ".//*[@id='bankList']/p[.='%s']";

String.format(bank, "ANZ"); // ".//*[@id='bankList']/p[.='ANZ']"
String.format(bank, "HSBC"); // ".//*[@id='bankList']/p[.='HSBC']"
String.format(bank, "Barclays"); // ".//*[@id='bankList']/p[.='Barclays']"
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s