Watir点击下拉菜单

时间:2014-02-10 17:43:56

标签: javascript jquery selenium watir watir-webdriver

我是网络应用自动化测试的新手。我正在使用watir-webdriver来自动化我们的应用程序功能测试。 我会用我的javascript下拉菜单来测试Watir就像知道我一样。我只是无法过去,每次尝试都会导致错误。

关于一个提示,我将非常感激

<section class="price-calculation" data-view="Forms.Pricecalculation,Forms.HelpInfo">
            <form action="/index.php" method="post" class="">
                    <input type="hidden" name="tx_bodpricecalculation_pi1[controller]" value="priceCalc">

                            <input type="hidden" name="tx_bodpricecalculation_pi1[action]" value="calculate">
                            <input type="hidden" name="type" value="54321">                         


                    <input type="hidden" name="tx_bodpricecalculation_pi1[isEditor]" value="0">

                    <input type="hidden" name="tx_bodpricecalculation_pi1[binding]" id="binding" value="">

                    <section class="input-group-container select-casade clearfix">
                        <div class="input-group product first">
                            <div class="input-fields">
                                <select name="tx_bodpricecalculation_pi1[product]" data-required="" id="selFNF" class="chzn-done" style="display: none;">
                                    <option value="" selected="selected" disabled="">ProduktNEU</option>
                                    <option value="FunNEU">FunNEU</option>
                                    <option value="ClassicNEU">ClassicNEU</option>
                                    <option value="ComfortNEU">ComfortNEU</option>
                                </select><div id="selFNF_chzn" class="chzn-container chzn-container-single chzn-container-single-nosearch" style="width: 76px;" title=""><a href="javascript:void(0)" class="chzn-single"><span>Comfort</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" readonly=""></div><ul class="chzn-results" tabindex="-1"><li id="selFNF_chzn_o_0" class="disabled-result" style="">Produkt</li><li id="selFNF_chzn_o_1" class="active-result" style="">Fun</li><li id="selFNF_chzn_o_2" class="active-result" style="">Classic</li><li id="selFNF_chzn_o_3" class="active-result result-selected" style="">Comfort</li></ul></div></div>
                            </div>

                                    <a class="btn-help" href="#" tabindex="-1" data-helpid="731"></a>

                            <div class="error-message">
                                <span class="desktop">Bitte</span> Ergänzen Sie die Angaben
                            </div>
                        </div>

第一个测试代码

    browser.select_list(:class => 'chzn-done').select('Fun')

首次测试输出

    Test Suite
    New Test Case (FAILED - 1)
    Failures:
    1) Test Suite New Test Case
    Failure/Error: browser.select_list(:class => 'chzn-done').select('FunNEU')
    Selenium::WebDriver::Error::ElementNotVisibleError:
    Element is not currently visible and so may not be interacted with
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-                 profile20140212-5829-7ai1pp/extensions/fxdriver@googlecode.com/components/command_processor

第二个测试代码

    browser.select_list(:name => 'tx_bodpricecalculation_pi1[product]').select('Fun')

Second Test-OutputTest Suite

    Test Suite
    New Test Case (FAILED - 1)
    Failures:
    1) Test Suite New Test Case
    Failure/Error: browser.select_list(:name =>         'tx_bodpricecalculation_pi1[product]').select('FunNEU')
    Selenium::WebDriver::Error::ElementNotVisibleError:
    Element is not currently visible and so may not be interacted with
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-        profile20140212-5829-        ry619a/extensions/fxdriver@googlecode.com/components/command_processor.js:8179:in         `fxdriver.preconditions.visible'
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-        profile20140212-5829-ry619a/extensions/fxdriver@googlecode.com/components/command_processor.js:10814:in `DelayedCommand.prototype.checkPreconditions_'

我得到以下测试根本不去。 =&GT;点击PRODUKTNEU =&GT;选择FUNNEU

最后是发生,计算产品FUNNEU。只有部分和PRODUKTNEU和FUNNEU会产生问题。

关于你的帮助我将非常感激

1 个答案:

答案 0 :(得分:1)

示例html中给出的选择列表的显示样式为none。因此,它不被视为可见。

您实际上想要与选择列表之后的内容进行交互。 “下拉列表”实际上是一个链接,“选项”是实际的li元素。

以下内容适用于实际页面:

require 'watir-webdriver'

b = Watir::Browser.new
b.goto 'http://www.bod.de/autoren/buch-veroeffentlichen/preiskalkulation.html'

# This is the div containing the "dropdown" you want to work with.
input_field = b.div(:class => 'product')

# Click the link to expand the dropdown
input_field.link(:class => 'chzn-single').click

# Click the related li element
input_field.li(:text => 'Fun').click