user1405338
user1405338

Reputation: 189

watir webdriver get into iframe and get src of elements and click on link

With Watir-Webdriver I want to go change the focus to the iframe and get the link that is inside it.

Here is the html code

<iframe id="top_right" src="otherwebsite.com/need content src">
<a href="need this"> <img src="need this" /> </a>

So what I would like is to go into the iframe, get the src of it, capture the href and the src from the img element and in the end click on these elements retrieving the data.

This is my attempt using Ruby:

require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'somesite.com'
b.wait
f = b.frame(:id => 'top_right').link(:index => 1).click

I have got until here but unfortunately i still get the following response:

in `assert_exists': unable to locate element, using {:index=>1, :tag_name=>"a"} (Watir::Exception::UnknownObjectException)

so if anybody have some help it would be great tnx.

Upvotes: 2

Views: 5099

Answers (1)

Željko Filipin
Željko Filipin

Reputation: 57262

You are trying to click the second link (:index=>1) in the frame. Looks like the frame does not have two links. Try clicking the first link (:index=>0):

b.frame(:id => 'top_right').link(:index => 0).click

Upvotes: 4

Related Questions