我们的网站上有w2ui 下拉元素,我想使用 selenium IDE 运行脚本进行测试,我已经记录了步骤,但是在运行该脚本时出现错误(未找到元素)。有什么方法可以处理 Selenium IDE 中的 w2ui 元素(特别是下拉列表)。我已经尝试过 xpath,仍然没有在下拉列表中选择值。
2 回答
0
我使用 JavaScript 得到了解决方案。Command - runScript和 Target -document.getElementById('DropdownId').value='Dropdown item value'通过使用它被选中。
于 2016-01-18T06:34:54.763 回答
0
在某些情况下,记录的 Selenium IDE 可能无法正确识别元素。在这些情况下,用户需要修改脚本以确保正确识别和输入元素。
请参考以下示例。录制的脚本无法选择 w2ui 下拉列表。我更新了脚本,以便正确识别元素并选择它。
您能否也更新您的脚本,以便在执行 IDE 时可以在正确的元素上工作?
在 Selenium 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://w2ui.com/" />
<title>Recorded Script</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Recorded Script</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/web/docs/form/fields-list</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=input[type="text"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=tr.w2ui-item-odd.w2ui-selected > td.menu-text</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>//input[@type='combo']</td>
<td>Testing</td>
</tr>
</tbody></table>
</body>
</html>
更新的脚本
我修改了脚本以通过类名正确识别 w2ui 下拉列表并正确输入字段下拉列表。当我在 Selenium 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://w2ui.com/" />
<title>Updated script</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Updated script</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/web/docs/form/fields-list</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>class=w2ui-icon icon-search</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>class=w2ui-select w2field</td>
<td>Andrew Johnson</td>
</tr>
<tr>
<td>storeValue</td>
<td>class=w2ui-select w2field</td>
<td>x</td>
</tr>
<tr>
<td>echo</td>
<td>${x}</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>//input[@type='combo']</td>
<td>Testing</td>
</tr>
<tr>
<td>storeValue</td>
<td>//input[@type='combo']</td>
<td>y</td>
</tr>
<tr>
<td>echo</td>
<td>${y}</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
于 2016-01-09T13:22:00.213 回答