是否可以与 selenium2 中的隐藏元素进行交互?

发布于 2024-10-21 13:52:23 字数 116 浏览 6 评论 0原文

我需要在网页的隐藏输入字段中设置值,我正在使用 Selenium 2。 我尝试使用 webelement.sendKeys(value),但它不起作用。

有人能告诉我该怎么做吗?

谢谢。

I need set value in Hidden inputfield of my webpage, I am using Selenium 2.
I tried with webelement.sendKeys(value), but its not working.

Can anybody tell me how to do this ?

Thanks.

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

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

发布评论

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

评论(2

夏夜暖风 2024-10-28 13:52:23

这个问题似乎有点不合常理。 Selenium 正在模拟基于用户的交互。因此,期望用户编辑页面上的隐藏元素是毫无意义的。但也许你应该说为什么需要这个以及你想用这个函数做什么,这样可以更容易地找到一些解决方法。

That question seems a little bit out of the box. Selenium is simulating user-based interactions. So, that's pointless to expecting from a user editing hidden elements on the page. But may be you should say why do you need this and what are you trying to do with this function, it can be more easy to finding some workarounds for it.

乖乖公主 2024-10-28 13:52:23

您无法使用元素方法修改隐藏对象。相反,将脚本发送到驱动程序:


@driver.execute_script("document.getElementById('context-menu-upload').value=#{value}")

这是文档:execute_script(script, *args)

要使用 xpath,请尝试以下操作:
有没有办法使用 XPath 获取元素Selenium WebDriver 中的 JavaScript?

You can't modify the hidden object using element methods. Instead, send script to the driver:


@driver.execute_script("document.getElementById('context-menu-upload').value=#{value}")

Here is the documentation: execute_script(script, *args)

To use xpath instead, try this:
Is there a way to get element by XPath using JavaScript in Selenium WebDriver?

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