简体   繁体   中英

Checking a checkbox using Ruby/Watir

I'm trying to automate pulling some data requests from LinkedIn each Friday, but I need to check specific checkboxes to request only relevant data.

After going through the documentation and multiple posts I still cannot seem to solve this issue.

The specific request page is under LinkedIn's privacy page where you request to download all of your data.

Here's the checkbox line of code:

browser.checkbox(id: 'file_group_INVITATIONS').set(true)

I've also tried setting it to false, using the value rather than id as well.

Trying to set the checkbox will give the error:

Selenium::WebDriver::Error::UnknownError : unknown error: Element <input type="checkbox" name="requestedFiles[]" id="file_group_INVITATIONS" value="INVITATIONS"> is not clickable at point (420, 481). Other element would receive the click: <label for="file_group_INVITATIONS">...</label>

LinkedIn wanted to style their checkbox, so they actually place a label on top of the actual checkbox element. As a user, when you are clicking the "checkbox", you are actually clicking the label element. This is what the error message is referring to when it talks about another element receiving the click.

You can do the same in Watir. The label is properly associated with the checkbox, which allows you to simply do:

browser.checkbox(id: 'file_group_INVITATIONS').label.click

Or more directly:

browser.label(:for => 'file_group_INVITATIONS').click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM