Wednesday, May 18, 2011

Iframes

For testing pages with iframes, I would suggest using watir-webdriver. It has better support for iframes than Watir.

To access an element in an iframe:

$ie.frame(:id, 'iframe').text_field(:id, 'mytextfield').when_present.set "hello"

Watir-webdriver driver has some good methods for waiting:

.when_present.set - do something when element is present
.wait_until_present - wait until element is present
.wait_while_present - wait until element disappears

To change focus back to main page from an iframe:

$ie.frame(:index, 0).locate

If you are using Google Chrome, you might have problems with text fields. To enter a value in a text field, try:

$ie.frame(:id, 'iframe').text_field(:id, 'mytextfield').set "abcdef"
$ie.frame(:id, 'iframe').text_field(:id, 'mytextfield').set("abcdef")

No comments:

Post a Comment

Post a Comment