views:

29

answers:

2

I'm trying to get element by name, and I have a problem

This is a element from amazon site:

<input type="text" style="width: 100%; background-color: rgb(255, 255, 255);" title="Search for" size="50" value="" name="field-keywords" class="searchSelect" autocomplete="off" id="twotabsearchtextbox">

and this is how I'm trying to get this element by its name:

<?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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case"&gt;
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.amazon.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>open</td>
    <td>/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>twotabsearchtextbox</td>
    <td>some keyword</td>
</tr>
<tr>
    <td>verifyElementPresent</td>
    <td>document.Forms[0].Element[&quot;field-keywords&quot;]</td>
    <td></td>
</tr>

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

But It gives me false :/ Could You suggest me some solution ?

I'm using 1.07 and FF 3.6.10

+1  A: 

You can change your verifyElementPresent to either "get by name"

<tr>
    <td>verifyElementPresent</td>
    <td>name=field-keywords</td>
    <td></td>
</tr>

or using XPath:

<tr>
    <td>verifyElementPresent</td>
    <td>xpath=//form//input[@name=&quot;field-keywords&quot;]</td>
    <td></td>
</tr>

Simple forms are:

  1. verifyElementPresent | name=field-keywords

  2. verifyElementPresent | xpath=//form//input[@name="field-keywords"]

ZloiAdun
A: 

The most simple way is to use JavaScript DOM reference:

verifyElementPresent | document.getElementsByName('field-keywords')[0]
p0deje