2500mA
2500mA

Reputation: 99

invalid attribute: :for (Watir::Exception::MissingWayOfFindingObjectException)

using Watir has the title error Need to set checkbox:

<label for="adr-eq" class="checkbox">Ok</label>

it works for:

ff.element(:css => 'label.checkbox:nth-child(12)').click

but why it doesn't work for:

ff.checkbox(:for => 'adr-eq').set
ff.element(:for => 'adr-eq').click

Upvotes: 0

Views: 483

Answers (1)

Justin Ko
Justin Ko

Reputation: 46826

Watir only allows locating elements using attributes that are valid for the element type (based on the HTML specifications). The for attribute is not valid for all elements or input elements. As a result, you get the Watir::Exception::MissingWayOfFindingObjectException.

If you look at the HTML you are trying to interact with, as well as the working CSS-selector, the element type is a label. The for attribute is valid for labels (and a couple of other elements). As a result, if you tell Watir to locate a label element, you can then use the :for locator.

To click the label using the for attribute:

ff.label(:for => 'adr-eq').click

If you want to use the Checkbox#set method, you will need to locate the element by the id attribute, which should match the for attribute:

ff.checkbox(:id => 'adr-eq').set

Upvotes: 1

Related Questions