2010-10-20 6 views
0

Je suis en train de faire élément par son nom, et j'ai un problèmeobtenir par son nom par le sélénium IDE

Ceci est un élément à partir du site amazon:

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

et voici comment je m essayant d'obtenir cet élément par son nom:

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

Mais il me donne de faux:/Pourriez-vous me suggérer une solution?

J'utilise 1,07 et FF 3.6.10

Répondre

2

Vous pouvez modifier vos verifyElementPresent soit à "obtenir par nom"

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

ou en utilisant XPath:

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

formes simples sont:

  1. verifyElementPresent | name=field-keywords

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

1

La façon la plus simple est d'utiliser JavaScript DOM Référence:

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