WebDriver Set value to Hidden Input

9,198 views
Skip to first unread message

Benjamin

unread,
Jul 28, 2011, 4:44:01 AM7/28/11
to Selenium Users
Hi,

I try to set a value to a hidden Input. But i get the following error
message:

org.openqa.selenium.ElementNotVisibleException: Element is not
currently visible and so may not be interacted with
Build info: version: '2.0.0', revision: '12817', time: '2011-07-07
19:14:34'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_15'
Driver info: driver.version: RemoteWebDriver

Thats my code:

selenium.findElement(By.name("UseGlobalApproval")).sendKeys("1");

and thats the hidden input:

<input type="hidden" name="UseGlobalApproval" value="0">

Is there any way to interact with a hidden input? Thanks a lot for
your help!

Chris Poulsen

unread,
Jul 28, 2011, 5:04:14 AM7/28/11
to seleniu...@googlegroups.com
Hi,

This can be done using javascript. Something like the following (not tested).

((JavascriptExecutor) webDriver).executeScript("document.getElementsByName('UseGlobalApproval').item(0).value = '1';");

Personally i would probably prefer adding an id and use getElementById instead of relying on name.

HTH. 

--
Chris

Jim Evans

unread,
Jul 28, 2011, 5:43:05 AM7/28/11
to Selenium Users
Since a user wouldn't be able to interact with your hidden element,
WebDriver can't either. You might be able to use JavaScript to do
this.

Benjamin

unread,
Jul 29, 2011, 5:29:42 AM7/29/11
to Selenium Users
Thanks a lot, that works!

Abhishek Sharma

unread,
Oct 2, 2018, 2:34:25 AM10/2/18
to Selenium Users
Hi,

I am trying to sendKeys in text filed. But nothing is happening and tried all the ways like Action class , executeScript also: - 

Code is : 

JavascriptExecutor js = (JavascriptExecutor) driver;  

js.executeScript("document.getElementsByName('message-to-send')[0].setAttribute('type', 'text');");


hidden input: 

<textarea name="message-to-send" id="message-to-send" placeholder="Type your message" rows="1" tabindex="-1" class="hide"></textarea>
<input type="hidden" autofocus="true">


Reply all
Reply to author
Forward
0 new messages