Selenium - 存储隐藏变量

发布于 2024-08-23 04:03:11 字数 596 浏览 3 评论 0原文

我们正在使用 Junit + Selenium 来测试我们的网页。但我们遇到了一个问题。

我需要使用 Selenium 解析隐藏字段中的值。
隐藏字段的 HTML

我使用以下 XPath
//input[@name='secretId']/@value

我需要抓取该隐藏变量并使用 XPath 存储它,并在脚本中进一步使用它。

我如何使用硒来做到这一点?

我尝试过

String SecretId = selenium.getText("//input[@name='secretId']/@value");
返回空字符串

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

XPath 是正确的,我已经使用 Firefox 中的 XPath 检查器验证了这一点,

谢谢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江心雾 2024-08-30 04:03:11

找到答案
String SecretId = selenium.getValue("//input[@name='secretId']");

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

拿命拼未来 2024-08-30 04:03:11

我已经得到了使用 WebDriver 获取值的答案:

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文