我正在尝试使用以下方法单击链接,但链接存在于表的第二页而不是第一页。我想知道如何通过搜索表格的所有页面中的链接并单击所需的链接来使方法通用?
table(:grid){div_element(:class =>' flexigrid') .table_element(:id =>' segmentGridContainer')}
def click_edit_link(name,label)
date = Time.now.strftime('%d-%b-%Y')
label_text = label + date
grid_element.cell_element(:text => /#{label_text}/)
.parent
.link_element(:text => name )
.click
end
答案 0 :(得分:0)
借鉴How to click link in a table based on the text in a row
提供的答案class MyPage
include PageObject
table(:grid_table, :class => 'basicGridTable')
link(:next, #add the identifier for your 'next page' link)
def click_edit_link(name,label)
date = Time.now.strftime('%d-%b-%Y')
label_text = label + date
matched_row = locate_row_by_text(label_text)
matched_row.link_element(:text = > name).click
end
def locate_row_by_text(text_value)
#find the row that matches the text you are looking for
matched_row = grid_table_element.find { |row| row.text.include? text_value }
#You'll need to handle the case where you're on the last page, but didn't find the value you were looking for
next.click() if matched_row.nil?
matched_row
end
end