I cannot select a link item using Watir

Here is the Watir code I'm using:

require 'watir-classic' browser = Watir::IE.new browser.link(:class, "Wizardbutton").exists? 

Here is the part of the HTML page containing the link I'm 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 the error that the link element does not 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 do not see this. Is the built-in span tag losing something? I also tried to choose to use href, and that didn't work either. Any understanding would be greatly appreciated!

+4
source share
2 answers

OK secret solved. Iframe is a major issue when working with Watir. Elements that are part of the iframe are not displayed unless you specifically selected the iframe, and then select the element in the iframe. So, for example, the code

 browser.frame(:name, "nameOfFrame").link(:class, "Wizardbutton") 

means to give me an iframe with the name attribute "nameOfFrame", and then select the link with the class attribute "Wizardbutton".

+3
source

I also encounter the same errors. On several occasions, watir could not find the browser control if it is present inside div tags or tables. In your case, communication management is placed inside the table. Please try this

 browser.table(:class=> "classname").link(:class => "Wizardbutton") 

Hope this helps you

+2
source

Source: https://habr.com/ru/post/1440060/


All Articles