2010-10-20 95 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]