Here is the Watir code I am using:
require 'watir-classic'
browser = Watir::IE.new
browser.link(:class, "Wizardbutton").exists?
Here is a portion of the HTML of the page containing the link I am trying to check if exists.
<tr>
<td align="left" style="vertical-align: top;">
<a class="Wizardbutton"href="javascript:parent.showPopup('/web/wizard.html');window.focus();">
<span>Add new Team</span>
</a>
</td>
</tr>
The error I am getting is:
Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_name=>["a"], :class=>"Wizardbutton"}
Why am I getting an error that the link element doesn’t exist when I can clearly see it in the HTML source? I have successfully clicked on other links on the page but for some reason I cannot see this one. Is the embedded span tag messing something up? I have also tried to select using href and that didn’t work either. Any insight would be greatly appreciated!
OK the mystery is solved. Iframes are a major gotcha when working with Watir. Elements that are part of an iframe are not visible unless you specifically select the iframe and then select the item in the iframe. So for example the code
means give me the iframe with the name attribute “nameOfFrame” and then select the link with the class attribute of “Wizardbutton”.