1

I need to pass values from excel sheet ( stored in variable api ) to XPATH in eclipse (java - Selenium).

I tried several options but none works. Please guide.

Here is my line of code.

String appcode = //input[contains(@id,'app') and contains(@type,'text') and ancestor::div[contains(@id, '+api+')]]

When i hardcode the value of api as below it works.

String appcode="//input[contains(@id,'app') and contains(@type,'text') and ancestor::div[contains(@id, 'setmember')]]";

Isnt it this easy?

Appreciate your help

pk

0

2 Answers 2

3

you probably did not end the String constructor properly. Try this:

String appcode = "//input[contains(@id,'app') and contains(@type,'text') and ancestor::div[contains(@id, '" +api+" ')]]";

My assumption is, that api variable is type String

Sign up to request clarification or add additional context in comments.

1 Comment

Also, a quick start guide (a first link from Google) on String concatenation so you know what's happening: java-samples.com/showtutorial.php?tutorialid=217
0

you can use \" so you would have something like

String appcode ="//input[contains(@id,\" "+[VARIABLE]+ " \")[..] ";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.