0

I cannot figure out a way to interact with the highlighted HTML:

buy item in js modal

When I click on a link, an interactive modal appears, which has a table to allow user to buy parts. Also, the modal has links that open up new sections within the modal.

I have tried to write step definitions but cannot get test to pass. See below for my (latest attempt) code:

When /^I click on the Buy icon of loan part selected$/ do
  @browser.div(:id, 'modal_loan_parts_table').link(:text, 'Buy').click
end

The error I keep getting is element not located. Can someone please direct me to enlightenment?

Here is the error that occured:

  unable to locate element, using {:id=>"modal_loan_parts_table", :tag_name=>"div"} (Watir::Exception::UnknownObjectException)
  ./step_definitions/secondarymkt_buying_lp.rb:62:in `/^I click on the Buy icon of loan part selected$/'
  secondarymkt_buying_lp.feature:27:in `When I cllick on the Buy icon of loan part selected'

Many Thanks Guys!

Azher
  • 493
  • 5
  • 18
  • 1
    What is the full error? And are you sure the div id is `modal_loan_parts_modal` - it is not in the part of the html shown? – Justin Ko Jan 24 '13 at 17:47
  • 1
    Another possibility: The "modal" that appears is a section of HTML contained in an iframe? – Abe Heward Jan 24 '13 at 19:35
  • Please provide link to the page, if it is public. Or link to a similar public page. – Željko Filipin Jan 25 '13 at 08:48
  • Hi folks, apologies for the div id, it's actually 'modal_loan_parts_table'. – Azher Jan 25 '13 at 09:06
  • Hi Željko, unfortunately I can't provide a link to the page and we don't have a page on our site with similar functionality. It's actually a complete re-work of one of the sites hence no examples. sorry – Azher Jan 25 '13 at 09:08
  • I could use xpath, but I really don't want to and would rather use it as a last resort. :) – Azher Jan 25 '13 at 09:26

1 Answers1

0

I found the solution without using xpath. Here is my code and it works:

When /^I click on the Buy icon of loan part selected$/ do
  @browser.div(:id, 'details-ajax-modal').wait_until_present
  @browser.div(:id, 'details-ajax-modal').exists?
  @browser.link(:class, 'modal-buy').wait_until_present
  @browser.link(:class, 'modal-buy').click
end

Many thanks to everyone.

Azher
  • 493
  • 5
  • 18
  • 2
    This seems more complicated than it has to be. I would think you could just do `@browser.link(:class, 'modal-buy').when_present.click`? – Justin Ko Jan 25 '13 at 13:49
  • Used @browser.link(:class, 'modal-buy').when_present.click, unfortunately this step did not work. When running the test, it could not find the element. I know my code is not pretty, but it's doing the job without using xpath :). Once again many thanks Justin for taking the time out to help me out. – Azher Jan 28 '13 at 10:49