【问题标题】:how to select "w2ui dropdown" elements in Selenium IDE?如何在 Selenium IDE 中选择“w2ui 下拉菜单”元素?
【发布时间】:2016-04-13 03:30:30
【问题描述】:

我们的网站上有 w2ui dropdown 元素,我想使用 selenium IDE 运行脚本进行测试,我记录了步骤,但在运行该脚本时出现错误(未找到元素)。有什么方法可以处理 Selenium IDE 中的 w2ui 元素(特别是下拉列表)。我已经尝试过 xpath,但仍然没有在下拉列表中选择值。

【问题讨论】:

  • 这对您有帮助吗?我认为您需要使用 moveToElement 命令来打开下拉列表,然后再选择其中的任何内容。 How to hover over an element
  • 实际上我使用的是 selnium IDE 而不是 webdriver 所以 moveToElement 命令不存在。 w2ui 有自己的自定义下拉菜单。所以 selenium IDE 无法与之交互。 selenium IDE 是否有任何特定的插件可以与 w2ui 元素或任何其他方式交互.. (“w2ui.com/web/docs/form/fields-list"- 了解有关 w2ui 下拉元素的更多信息)。请参考这个我使用相同的下拉菜单在我的应用程序中并希望 selenium IDE 与之交互。

标签: selenium testing automated-tests selenium-ide w2ui


【解决方案1】:

在某些情况下,记录的 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=&quot;text&quot;]</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=tr.w2ui-item-odd.w2ui-selected &gt; 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>

【讨论】:

  • 您好,感谢您的帮助,但我仍然收到错误消息。无法找到正确的类名。 pastebin.com/akJqpcAM 请参考这个链接(我的原始录制演示脚本),我已经上传了我的脚本,在 css=td.menu-text处出现错误> 。当我点击下拉选项时,这条线被记录下来。
  • 您可以在下拉列表框中键入值(而不是单击 css=td.menu-text 并单击 name=save)吗?
  • 我已经尝试过了,但没有得到预期的 o/p。 imagebin.ca/v/2TOIKHgHSuXd 请参考这个链接 我已经在品牌下拉列表中添加了 GUI 的屏幕截图没有被选中。 pastebin.com/tR5nPkQS这是我的新脚本,我按照你说的做了修改。脚本运行,但所选值(通过脚本)无法显示在下拉控件中(//input[@type='text'] Amul)。你能帮我找到下拉值类吗(下拉值是在运行时生成的)
  • 然后我需要更多信息。我需要品牌字段的完整 xml。 Amul 是下拉列表中的值之一吗?
  • 是的..它的值是我们在运行时得到的,但我直接输入它没有记录(因为记录不适用于值选项)。
【解决方案2】:

我使用 JavaScript 得到了解决方案。 Command- runScript 和 Target- document.getElementById('DropdownId').value='Dropdown item value' 使用它被选中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多