0
votes

Been looking through lot of the questions and forums, but I am unable to figure out. Pretty fresh with Watir.

Doing a test on a webpage where a user can create groups (the solution is built within the kendoui framework)

To create a group.

browser.button(:id => "add_group").click

browser.text_field(:id => "group_name").set("delete")

browser.button(:id => "add_group").click

Group is created, then i want to delete the group. if a user mouseover the new group a thrashcan symbol appears on the right side of the group container and on click the group is deleted.

Code:

<div id="left_pane" class="side_panel k-pane k-scrollable" style="position: absolute; top: 0px; width: 220px; height: 724px; left: 0px;">
<ul id="toolbox_panel" class="k-widget k-reset k-header k-panelbar" data-role="panelbar">
    <li class="k-item k-state-default k-first">
    <li id="group_ungrouped" class="k-item k-state-default" data-role="droptarget">
    <li id="group_delete" class="k-item k-state-default k-last" data-role="droptarget">
    <span class="k-link k-header k-state-hover">delete</span>
        <!--snipp below is only visible on hover of delete element-->
        delete
        <span class="minicon remove_pod"></span>    
        </li>

Couple of things i've tried with watir:

browser.div(:id, 'left_pane').ul(:id, 'toolbox_panel').li(:id, 'group_delete').span(:class, 'minicon remove_pod').fire_event "onclick"

gives the following:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.1/lib/watir-webdriver/elements/element.rb:36 5:in assert_exists': unable to locate element, using {:class=>"minicon remove_pod", :tag_name=>"spa n"} (Watir::Exception::UnknownObjectException) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.1/lib/watir-webdriver/elements/ element.rb:247:infire_event' from C:/bin/scripts/ruby/sm_groups.rb:34:in `'

Other tests:

browser.div(:id, 'left_pane').ul(:id, 'toolbox_panel').li(:id, 'group_delete').span(:class, /k-state-hover/).span(:class, 'minicon remove_pod').fire_event "onclick"

browser.div(:id, 'left_pane').ul(:id, 'toolbox_panel').li(:id, 'group_delete').span(:class, 'k-link k-header k-state-hover').span(:class, 'minicon remove_pod').click

I am a little bit at loss on how to hover the "group_delete" and then when hovering find the delete/minicon remove_pod and click it in order to delete the created content.

Please let me know if more information is required.

Best regards

2
The error message says "unable to locate element", so make sure you are identifying the element correctly.Željko Filipin

2 Answers

2
votes

To hover and element, try this:

browser.element(how, what).hover
1
votes

Decided to modify the code in the webpage so the last span class is visible in firebug without mouse over.

Watir does the trick with this:

browser.element(:id, 'left_pane')
    .ul(:id, 'toolbox_panel')
    .li(:id, 'group_delete')
    .span(:class, 'k-link k-header')
    .span(:class, 'minicon remove_item')
    .click()