3

Can somebody please help me on the following?

I want to click on a button who has the text "Resume Scanning". In the below script. Instead of the hard coding (Resume Scanning), how can I pass the value from property file?

driver.findElement(by.xpath("//button[contains(.,'Resume Scanning')]"));

Thanks, Kannan C

4 Answers 4

2

try as follows:

String label = "Resume Scanning";
driver.findElement(By.xpath("//button[contains(.,'" + label + "')]"));

Or using String.format:

String string = String.format("//button[contains(.,'%s')]", label);
driver.findElement(By.xpath(string));

Reference:

  1. Java - Including variables within strings?
Sign up to request clarification or add additional context in comments.

1 Comment

I used this one String label = "Resume Scanning"; driver.findElement(By.xpath("//button[contains(.,'" + label + "')]"));
0

You can use following java code to read from properties file

FileInputStream in = new FileInputStream("location of properties file");
Properties prop = new Properties();
prop.load(in);
String buttonText=prop.getProperty(propertyName);
driver.findElement(By.xpath(".//button[contains(text(),'"+buttonText+"')]"));

Comments

0

You can use a property file to read the text value. Here is an example:

inputParams.properties
----------------------
buttonLabel=Resume Scanning

Use the below sample code to read data from the property file:

FileReader reader=new FileReader("inputParams.properties");  
Properties p=new Properties();  
p.load(reader);  
System.out.println(p.getProperty("buttonLabel"));

Hope it helps.

Comments

0

By.xpath("//button[contains(.,'Add Strategy')]")

By.xpath("//button[contains(.,'Submit')]")

2 Comments

It may be helpful to provide some additional details, that explain what this code is doing, and how exactly this addresses the OP's question.
Its is html base xpath finder when driver find any button which text is same with define text it will get access.

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.