0

Using Selenium and Chrome, I'm attempting to check a box located within a table. The table contains 2 checkboxes but they act as radio buttons, in that if I click one, the other will uncheck.

I've tried a variety of methods, which include the following:

Const CHECKED_STATE As String = "Ag-icon ag-icon-checkbox-checked" findElementByClassName("ag-selection-checkbox").fireEvent("CHECKED_STATE") findElementbyXPath("//span[@class=ag-icon ag-icon-checkbox-checked'])[1]").Click findElementbyXPath(".//div[@class='ag-body-container']").Click 

I'm not sure how to click the checkbox when the HTML code doesn't even have a checkbox type or an Id.

The HTML reads:

 <span class="ag-icon-checkbox"> <span class = "ag-icon ag-icon checkbox-checked ag-hidden"> <span class = "ag-icon ag-icon checkbox-unchecked"> <span class = "ag-icon ag-icon checkbox-undeterminate ag-hidden"></span> 

When I click on the checkbox, the unchecked and hidden lines of HTML will flip. So I'm guessing it's some sort of event that I have to trigger.

2
  • Do you need to toggle between them? Or only ever need to select the unchecked one?
    – QHarr
    CommentedNov 9, 2021 at 0:02
  • Only need to select the unchecked @QHarr.
    – Nahuatl
    CommentedNov 9, 2021 at 15:59

1 Answer 1

0

The following, depending on the rest of the html, should work to select the unchecked item and thereby toggle off the other item. It targets the class checkbox-unchecked:

driver.FindElementByCss(".ag-icon-checkbox .checkbox-unchecked").click 
6
  • I tried both with "ag-icon-checkbox" and "ag-icon ag-icon checkbox-unchecked" and it's throwing a "NoSuchElementError Element not found for Css=ag-selection-checkbox".
    – Nahuatl
    CommentedNov 9, 2021 at 15:18
  • 1
    Is your element inside a parent frame/iframe tag?
    – QHarr
    CommentedNov 9, 2021 at 15:58
  • yes, it appears so since I can see <iframe title="Application content" class... That's an option I'm looking into since I just found a question related to reCaptcha stating that I have to make the element clickable. This isn't a reCaptcha. It's just a table.
    – Nahuatl
    CommentedNov 9, 2021 at 16:04
  • you need to SwitchTo that iframe first
    – QHarr
    CommentedNov 9, 2021 at 19:21
  • Yes, that's what I'm trying to figure out now. I'm unsure of what the iframe name is.
    – Nahuatl
    CommentedNov 9, 2021 at 19:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.