Firefox V2.50.0的Webdriver问题

时间:2016-02-05 07:21:59

标签: java selenium selenium-webdriver

以下是正在测试的应用程序中的一个月下拉列表的HTML。

<div class="dd ddcommon form-control respstyled-select-monthAC ng-isolate-scope borderRadius" id="month2_msdd" tabindex="0" style="z-index: 1;">
    <div class="ddTitle borderRadiusTp"><span class="divider"></span><span class="ddArrow arrowoff" id="month2_arrow"></span>
        <span class="ddTitleText "  id="month2_title"><span class="ddlabel">month</span><span class="description" style="display: none;"></span></span></div><input type="text" id="month2_titleText" autocomplete="off" class="text shadow borderRadius" style="display: none;">
    <div class="ddChild ddchild_ border shadow" id="month2_child" style="z-index: 1; display: none; position: absolute; max-height: 288px; top: 28px;">
        <ul><li class="enabled _msddli_ selected"><span class="ddlabel">month</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span          class="ddlabel">January</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">February</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">March</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">April</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">May</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">June</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">July</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">August</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">September</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">October</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">November</span><div class="clear"></div></li>
            <li class="enabled _msddli_"><span class="ddlabel">December</span><div class="clear"></div></li></ul></div></div>

我使用以下脚本从下拉列表中选择1月选项:

driver.findElement(By.xpath(//*[@id="month2_arrow"])).click();
driver.findElement(By.xpath(//div[@id='month2_child']/ul/li[2]/span)).click();

这个代码将有两次点击从月份下拉列表中选择一月选项。这个工作正常,直到Selenium Webdriver 2.47。当我将selenium升级到2.50时,两个步骤都成功执行,但未选择该选项。

3 个答案:

答案 0 :(得分:0)

Selenium提供的接口为javascriptexecutor

你可以这样做: -

      WebElement element= driver.findElement("YOUR Locator"));
      JavascriptExecutor executor = (JavascriptExecutor) driver;
      executor.executeScript("arguments[0].click();", element);

希望它会对你有所帮助:)。

答案 1 :(得分:0)

替代方法是将焦点放在下拉列表中,然后使用sendKeys()方法键入所需月份的名称。这将选择月份并通过sendKeys()发送回车将确认您的选择。

答案 2 :(得分:0)

您可以下载firefox ESR。它的稳定版firefox。 目前支持的官方发行版是Firefox 38.6.0 ESR,与最新的Selenium Webdriver兼容。