Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - Store hidden variable

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?

like image 281
Jonas Söderström Avatar asked Nov 28 '25 08:11

Jonas Söderström


2 Answers

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

like image 103
Jonas Söderström Avatar answered Nov 29 '25 21:11

Jonas Söderström


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

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

like image 34
Ripon Al Wasim Avatar answered Nov 29 '25 23:11

Ripon Al Wasim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!