SmartSolution
SmartSolution

Reputation: 2348

is it possible to interact with hidden elements in selenium2?

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.

Upvotes: 2

Views: 959

Answers (2)

Marc Kubischta
Marc Kubischta

Reputation: 203

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?

Upvotes: 0

mirza
mirza

Reputation: 5793

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.

Upvotes: 1

Related Questions