作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 XPath 可以选择我的特定单选按钮项
HTML。我想通过使用
存储变量来表示我的 XPath 用于的文本
锁上。
这是我目前的设置
命令:点击
目标:
//*[contains(@for,'Page149.Question48.TypeChoiceOneAnswerRadioButton.holder_ctl02')
and text()="Below 70 – May be too low"]
//*[contains(@for,'Page149.Question48.TypeChoiceOneAnswerRadioButton.holder_ctl02')
and text()=${radioText}]
<!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>
<?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>
最佳答案
您需要在变量周围加上引号。
//*[contains(text(),'${Gender}')]
~/Library/Application Support/Firefox/Profiles/[your profile]/extensions/{a6fd85ed-e919-4a43-a5af-8da18bda539f}/chrome/content/selenium-core/scripts/
Selenium.prototype.doClick
doClick
上面的处理程序调用 BrowserBot.prototype.findElement
, 例如。 selenium.preprocessParameter(command.target)
预处理定位符字符串。 . selenium.preprocessParameter
可以在 selenium-api.js
中找到. XPathEvaluator
LOG.error("Useful debugging information");
$x("xpath/expr/with/stored/variables/replaced/accordingly")
在普通的 Firefox JS 控制台上。
关于selenium - 在 Selenium IDE 中,Locator 可以使用 XPath 和 storedVars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5825908/
我有一个 XPath 可以选择我的特定单选按钮项 HTML。我想通过使用 存储变量来表示我的 XPath 用于的文本 锁上。 这是我目前的设置 命令:点击 目标: //*[contains(@for,
我是一名优秀的程序员,十分优秀!