rubywatirwatir-webdriverpage-object-gemrspec-expectations

How to get text of selected option from select list without [ ] brackets


I use next command to get a text of selected option in select list:

@sltedStudy=page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)

But when I try to compare values:

expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy

it returns:

RSpec::Expectations::ExpectationNotMetError: expected: == ["SLC"]
     got:    "SLC"

How I can get a value of text from select list without [ ] brackets?


Solution

  • It looks like this line:

    @sltedStudy = page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)
    

    gives an array of text from selected options: ["SLC"]

    try changing your rspec to this:

    expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy.first
    

    or this:

    expect([page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text]).to be == @sltedStudy