我有一个XPath,它将选择我的 HTML中的特定单选按钮项。我想通过使用 存储的变量来表示我的XPath正在使用的文本锁定为 ,从而使我的定位器更加具有动态性。在Selenium IDE中,Locator可以使用XPath和storedVars
这是我的当前设置
命令:点击
目标:
//*[contains(@for,'Page149.Question48.TypeChoiceOneAnswerRadioButton.holder_ctl02')
and text()="Below 70 – May be too low"]
我想替换文字文本“低于70 - 可能太低“ 与一个变量。我提议的目标未能评估。我希望我 只是语法不正确。
我可以这样做吗?我可以在XPath定位器中使用存储的变量吗?
提议的目标:
//*[contains(@for,'Page149.Question48.TypeChoiceOneAnswerRadioButton.holder_ctl02')
and text()=${radioText}]
编辑:添加代码。我做了一个简单的HTML单选按钮列表示例,并隔离了我的Selenium命令。我在Firefox中使用Selenium IDE。我的命令示例有评论。
样本HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
</head>
<body>
<table border="0" class="srvy_radiobuttonlist" id="ctl00_cphSurveyControls_surveyCategoryPage_Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02">
<tbody>
<tr>
<td>
<input type="radio" checked="checked" value="Page51.Question5.Answer580" name="ctl00$cphSurveyControls$surveyCategoryPage$Page51.Question5.TypeChoiceOneAnswerRadioButton.holder$ctl02"
id="ctl00_cphSurveyControls_surveyCategoryPage_Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02_0"><label
for="ctl00_cphSurveyControls_surveyCategoryPage_Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02_0">Male</label>
</td>
<td>
<input type="radio" value="Page51.Question5.Answer581" name="ctl00$cphSurveyControls$surveyCategoryPage$Page51.Question5.TypeChoiceOneAnswerRadioButton.holder$ctl02"
id="ctl00_cphSurveyControls_surveyCategoryPage_Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02_1"><label
for="ctl00_cphSurveyControls_surveyCategoryPage_Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02_1">Female</label>
</td>
</tr>
</tbody>
</table>
</body>
</html>
嘲笑了硒IDE
<?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://localhost" />
<title>LocatorTest</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">LocatorTest</td></tr>
</thead><tbody>
<!--Select Male-->
<tr>
<td>click</td>
<td>//*[contains(@id,'Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02_0')]</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>Female</td>
<td>Gender</td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>${Gender}</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>javascript{ storedVars['Gender']}</td>
<td></td>
</tr>
<!--FYI, locates first item in radio collection-->
<tr>
<td>click</td>
<td>//*[contains(@for,'Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02')]</td>
<td></td>
</tr>
<!--Works to select female-->
<tr>
<td>click</td>
<td>//*[contains(@for,'Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02') and text()='Female']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//*[contains(@for,'Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02') and contains(text(),'Female')]</td>
<td></td>
</tr>
<!---- not found -->
<tr>
<td>click</td>
<td>//*[contains(@for,'Page51.Question5.TypeChoiceOneAnswerRadioButton.holder_ctl02') and contains(text(),${Gender})]</td>
<td></td>
</tr>
<!--Works to select female-->
<tr>
<td>click</td>
<td>//*[contains(text(),'Female')]</td>
<td></td>
</tr>
<!---- not found -->
<tr>
<td>click</td>
<td>//*[contains(text(),${Gender})]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
我添加了代码示例以帮助说明。您的意见不清楚您的意思。 – MADCookie 2011-04-29 19:28:37
我用Selenium IDE 1.0.10在Firefox 3.6.17上运行了你的测试。它成功运行。日志不适合评论,但这里是有用的部分。 #[info]执行:| store |女性|性别| #[info]执行:| assertTextPresent | $ {Gender} | | #[info]执行:| assertTextPresent | javascript {storedVars ['Gender']} | | 然后我将“女性”改为“香蕉”,并得到这个: #[info]执行:| store |香蕉|性别| #[info]执行:| assertTextPresent | $ {Gender} | | #[错误]假 – 2011-05-04 18:35:25