我需要在网页的隐藏输入字段中设置值,我使用的是 Selenium 2。我尝试使用 webelement.sendKeys(value),但它不起作用。
谁能告诉我该怎么做?
谢谢。
我需要在网页的隐藏输入字段中设置值,我使用的是 Selenium 2。我尝试使用 webelement.sendKeys(value),但它不起作用。
谁能告诉我该怎么做?
谢谢。
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,请尝试以下操作: Is there a way to get element by XPath using JavaScript in Selenium WebDriver?