page-object confirm not working

78 views Asked by At

I've searched and hacked and searched and hacked but have yet to come up with a solution. I am attempting to find an item in a table and click a Delete link which is in one of the cells on the right. My page-object code to find and click the appropriate link works like a champ, however, when the confirm popup comes up, the OK button is never clicked so the item is not deleted. My page-object is below. I added the "sleep 5" just to verify that I see the popup come up and it does. Should I not be seeing the popup at all?

 class ThingManagementPage
      include PageObject

      page_url "https://#{HOST_MAP['portal']}/customers/<%= params[:customer] %>/customer_things"
      link(:things_and_prefixes, :text => 'ASNs & Prefixes')
      link(:thing_sets, :text => 'AS Sets')
      table(:things, :css => '.table-condensed')
      links(:delete_thing, :title => 'Delete')
      links(:edit_thing, :title => 'Edit')

      def delete_thing(thing)
        found = false
        index = 0
        self.things_element.each do |row|
          if row[0].text == thing
            self.confirm(true) do
              self.delete_thing_elements[index-1].click
              sleep 5
            end
            found = true
            break
          end
          index += 1
        end
       fail "Failed to find and delete thing #{thing} on page!" unless found
      end
    end
1

There are 1 answers

0
CraigD On

I resolved this, however, this seems like more of a hack and something that should not be necessary when using page-object. Essentially, I replaced this:

        self.confirm(true) do
          self.delete_thing_elements[index-1].click
          sleep 5
        end

with calls to selenium-webdriver to switch to the popup window and click the OK button:

    self.delete_thing_elements[index-1].click
    @browser.switch_to.window("")
    @browser.find_element(:xpath => '//div[2]/button[2]').click