mattrock
mattrock

Reputation: 47

Watir click on drop down

I'm a newbie to web app automation testing. I'm using watir-webdriver to automate our functional testing with an application. I would my javascript drop down menu to test with Watir like to know as I do. I just can not get past and every attempt results in an error.

About one tip I would be very grateful

<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>

First Test-Code

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

First Test-Output

    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/[email protected]/components/command_processor

Second Test-Code

    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/[email protected]/components/command_processor.js:8179:in         `fxdriver.preconditions.visible'
    # [remote server] file:///var/folders/8m/3byyttvd4cxbqx22s60hvb4c0000gn/T/webdriver-        profile20140212-5829-ry619a/extensions/[email protected]/components/command_processor.js:10814:in `DelayedCommand.prototype.checkPreconditions_'

I get the following test simply not go. => Click on PRODUKTNEU => Select FUNNEU

At the end is to take place, a calculation for the product FUNNEU. Just the part and PRODUKTNEU and FUNNEU makes problems.

About your help I would be very grateful

Upvotes: 0

Views: 1627

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

The select list that was given in the sample html has a display style of none. As a result, it is not considered visible.

You actually want to interact with the content that comes after the select list. The "dropdown" is actually a link and the "options" are actual li elements.

The following works against the actual page:

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

Upvotes: 1

Related Questions