使用Selenium 1或2选择下拉列表

时间:2013-07-23 07:45:11

标签: selenium selenium-webdriver automated-tests junit4

我需要使用selenium单击此下拉列表来导航帧。我需要选择菜单和下拉列表中的链接。但是selenium.click不起作用。

手动执行: 鼠标悬停用于下拉列表的SUBSCRIBER链接/菜单 单击下拉列表中的所选链接/菜单

我需要通过Selenium自动化它。

这是来自firebug的元素检查器:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
      <!-- Generated by Python html module ($Revision: 1.6 $). -->

      <!-- charset : iso-8859-1 -->
    <head> … </head>
<frameset rows="78,62,32,*" frameborder="no" border="0">
    <frame scrolling="no" src="/html/header_frame.html" noresize="1" name="head_frame"></frame>
    <frame scrolling="no" src="/cgi-bin/main/title.cgi" noresize="1" name="titleframec"></frame>
    <frame scrolling="no" src="/cgi-bin/main/navigationframe.cgi" noresize="1" name="navFrame">#document<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
      <!-- Generated by Python html module ($Revision: 1.6 $). -->

      <!-- charset : iso-8859-1 -->
    <head> … </head>
    <body class="nav_frame" marginwidth="0" marginheight="0" onload="parent.bodyframe.location='/cgi-bin/service/subscriber/subscriberDetails.cgi';" topmargin="0" leftmargin="0"><script language="JavaScript"> … </script>
    <table class="nav_frame" cellspacing="0" cellpadding="0" border="0">
        <tbody>
        <tr>
            <td> … </td>
            <td><a onmouseout="MM_startTimeout();" onmouseover="MM_showMenu(menu_SUBS,0,0,null,'subscriber_bt');" href="javascript:;"><img width="125" height="32" border="0" alt="" src="/nav_images/subscriber_bt.jpg" name="subscriber_bt"></img></a></td>
            <td> … </td>
            <td> … </td>
            <td> … </td>
            <td> … </td>
            <td> … </td>
            <td> … </td>
            <td> … </td>
            <td> … </td>
       </tr>
       </tbody>
    </table>
    <script language="JavaScript"> … </script>
    <form name="navig" target="bodyframe" method="POST" action="/cgi-bin/service/subscriber/subscriberDetails.cgi"> … </form>
    </body>
    </html>
</frame>
<frame name="bodyframe">
</frame>
</frameset><noframes> … </noframes>
</html>

actual drop-down list

1 个答案:

答案 0 :(得分:1)

您需要使用Actions()Webdriver

Actions action = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("subscriber_element"))).moveToElement(driver.findElement(By.id("revealed_element"))).click().build().perform();