Yass
Yass

Reputation: 602

How to set value for hidden in filed in selenium script>

I'm novice in selenium script and trying to setup a value for a hidden field. After providing user id and password in the login form, i have to set a hidden field value (" <<--- HERE SET HIDDEN FIELD VALUE--->>").

I tried something like this

<tr>
    <td>type</td>
    <td>id=AppIDhidden</td>
    <td>test</td>
    <td>#SEP#id=AppIDhidden#SEP#name=AppIDhidden#SEP#css=#AppID#SEP#xpath=//input[@id='AppIDhidden']#XPATH#//form[@id='myLoginForm']/div[2]/div/div[2]/div/input#XPATH#//div[2]/div/input#XPATH##SEP#dom=document.forms[0].AppIDhidden#DOM#document.forms[0].elements[3]#DOM##SEP#</td>
    <td>0</td>
    <td></td>
    <td>field value</td>
</tr>

but didn't work, I got error "Element id=AppIDhidden is not visible".

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.example.com/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
    <td>newStep</td>
    <td>Loading - https://www.example.com/</td>
    <td></td>
    <td></td>
    <td>3825</td>
    <td>https://www.example.com/</td>
    <td></td>
</tr>
<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
    <td></td>
    <td>0</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>id=DisplayUserMask</td>
    <td>myuser</td>
    <td>#SEP#id=DisplayUserMask#SEP#name=DisplayUserMask#SEP#css=#DisplayUserMask#SEP#xpath=//input[@id='DisplayUserMask']#XPATH#//form[@id='myLoginForm']/div[3]/div/input#XPATH#//div/input#XPATH##SEP#dom=document.forms[0].DisplayUserMask#DOM#document.forms[0].elements[1]#DOM##SEP#</td>
    <td>0</td>
    <td></td>
    <td>Type DisplayUserMask</td>
</tr>
<tr>
    <td>type</td>
    <td>id=Password</td>
    <td>mypassword</td>
    <td>#SEP#id=Password#SEP#name=Password#SEP#css=#Password#SEP#xpath=//input[@id='Password']#XPATH#//form[@id='myLoginForm']/div[6]/div/input#XPATH#//div[6]/div/input#XPATH##SEP#dom=document.forms[0].Password#DOM#document.forms[0].elements[3]#DOM##SEP#</td>
    <td>isPassword</td>
    <td></td>
    <td>Type Password</td>
</tr>
<<--- HERE SET HIDDEN FIELD VALUE--->>
<tr>
    <td>newStep</td>
    <td>Click subLogin</td>
    <td></td>
    <td></td>
    <td>6070</td>
    <td>https://www.example.com/myhome</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>

Upvotes: 1

Views: 932

Answers (1)

alecxe
alecxe

Reputation: 473863

Use the runScript command:

<tr>
    <td>runScript</td>
    <td>document.getElementById('AppIDhidden').value='test'</td>
    <td></td>
</tr>

Upvotes: 2

Related Questions