是否可以与 selenium2 中的隐藏元素进行交互?
我需要在网页的隐藏输入字段中设置值,我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题似乎有点不合常理。 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.
您无法使用元素方法修改隐藏对象。相反,将脚本发送到驱动程序:
@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?