开发者

Selenium - Store hidden variable

开发者 https://www.devze.com 2022-12-21 03:46 出处:网络
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.

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

开发者_JAVA百科

Thanks?


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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消