3

We are using Junit + Selenium to webtest our webpage. But we have run into a problem.

I need to parse the value from a hidden field with Selenium.
HTML of hidden field
<input type="hidden" name="secretId" value="123456"/>
I use the following XPath
//input[@name='secretId']/@value

I need to scrape that hidden variable and store it using a XPath and use it further on down the script.

How do I do this with Selenium?

I have tried

String secretId = selenium.getText("//input[@name='secretId']/@value");
Returns empty string

String secretId = selenium.getEval("//input[@name='secretId']/@value");
Returns null

The XPath is correct, I have verified this with XPath Checker in Firefox

Thanks?

2 Answers 2

3

Found the answer
String secretId = selenium.getValue("//input[@name='secretId']");

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

2 Comments

How can I get the value by using WebDriver?
I don't know about Java, but this works in Python and might as well i Java: driver.find_element_by_name('something').value = 'some string'
1

I have got the answer to get the value by using WebDriver:

String secretId = driver.findElement(By.xpath("//input[@name='secretId']")).getText();

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.