Dennis Ferguson Dennis Ferguson - 1 year ago 79
Ruby Question

Selecting sort buttons on table

I have a table that I need to select the sort ascending and descending buttons. The html looks like this

<table id="results" class="list-table" width="100%" cellspacing="0" cellpadding="0">
<tr class="header-row ">
<th id="field_app_job_title" class="app_job_title ">
<th id="field_app_full_name" class="app_full_name ">
<th id="field_app_individual_workflow_states" class="v0_workflow_state_definition_id_sort ">
<th id="field_app_workflow_state_entrance_reason" class="v0_workflow_state_entrance_reason_sort ">
<span class="controls">
<span class="move_left"></span>
<span class="move_right" style="display: none;"></span>
<span class="sort_asc"></span>
<span class="sort_desc"></span>
<span class="remove"></span>
Workflow State Entrance Reason
<th class="action-menu"></th>

I have tried the following:

within_table 'results' do
find('Workflow State Entrance Reason').click_link('sort_asc')


within_table 'results' do

and even this, but none has located the element so far.

within_table 'results' do


Answer Source

Thanks for everyones input and sorry for my late response. Your answers led me down the correct path and I was able to resolve this. One problem was I didn't realize was that the sort elements did not appear until the mouse was hovering over the column.

within_table 'results' do
  find('#field_app_workflow_state_entrance_reason', text: 'Workflow State Entrance Reason').hover

This then gave a new error where I was getting this error

Capybara::Poltergeist::MouseEventFailed: Firing a click at co-ordinates [719.5, 438] failed. Poltergeist detected another element with CSS selector 'html div#container section#main div#main-content section.details div.subpage section#search_results table#results.list-table tbody tr.header-row th#field_app_workflow_state_entrance_reason.v0_workflow_state_entrance_reason_sort span.controls' at this position. It may be overlapping the element you are trying to interact with. If you don't care about overlapping elements, try using node.trigger('click').

A bit of research on the node.trigger and I was able to click the element like this without getting the error.

within_table 'results' do
  find('.v0_workflow_state_entrance_reason_sort span.controls .sort_asc').trigger("click")

I'm not sure if this is a great idea or not, but it seems to work for now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download