2010-10-20 101 views
0

我试图通过名字来获得元素,我有一个问题硒IDE的名字得到元素

这是从亚马逊网站元素:

<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"> 

,这是我怎么样m试图通过它的名字得到这个元素:

<?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.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> 

但它给了我false:/你能告诉我一些解决方案吗?

我使用的是1.07和FF 3.6.10

回答

2

你可以改变你的verifyElementPresent要么 “通过名称获得”

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

或使用XPath:

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

简单的形式是:

  1. verifyElementPresent | name=field-keywords

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

1

最简单的方法是使用JavaScript DOM参考:

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