0

I seem to be having an issue with Selenium clicking on a radio button but from the looks of it, it's not an input radio button but an image to look like a radio button. Any idea how I would click on triggerControl2 which is the top button to turn on Use an external certificate.

Radio button

Elements

<tr>
  <th>Certificate options</th>
  <td>
    <table class="middleAlign">
      <tbody><tr>
      <td><img id="triggerControl2" name="SSLCertModeImg" value="normal" onclick="this.guiAction();" src="../../../img/radio_off_normal.png" checked="false"></td>
      <td>Use an external certificate</td>
      </tr>
      <tr>
      <td><img id="triggerControl4" name="SSLCertModeImg" value="auto" onclick="this.guiAction();" src="../../../img/radio_on_normal.png" checked="true"></td>
      <td>Use a self-signed certificate (For test use)</td>
      </tr>
    </tbody></table>
  </td>
</tr>
1
  • 1
    can you show what locators have you tried so far that didn't work for you? Commented May 19, 2021 at 20:39

2 Answers 2

1

I'm not sure, possibly need to debug this, but I guess the locator for the triggerControl2 button is img[id="triggerControl2"] css_selector.
Or if you prefer XPath //img[@id="triggerControl2"]

Sign up to request clarification or add additional context in comments.

10 Comments

I have tried a wildcard for both css_selector and xpath, it's driving me up the wall. driver.find_element_by_css_selector("[id*='triggerControl2']").click() driver.find_element_by_xpath("//*[contains(@id, 'triggerControl2')]").click()
What this exactly means? I mean what error are you getting? Maybe your locators are not unique or you missing a delay / wait before that?
I just get the normal Unable to locate element on both on css_selectors and xpath, even with wildcards. Confusing the heck out of me.
Do you have a sleep / delay /wait before that code line? Maybe it is inside iframe?
yes has a 2 sec delay before the code, you know what could be in an iframe, didn't think of that
|
1

Try this css selector:

tr:nth-of-type(1) img[id*="triggerControl"][name='SSLCertModeImg']

Id seems to be auto-generated, that's why I added *.

To click use:

btn = driver.find_element_by_css_selector("tr:nth-of-type(1) img[id*="triggerControl"][name='SSLCertModeImg']")
driver.execute_script("arguments[0].click();", btn)

Radio-buttons sometimes are hard to click with Selenium.

5 Comments

This would be a nope driver.find_element_by_css_selector("img[id*='triggerControl']").click()
Updated the locator
still getting my usual Message: no such element: Unable to locate element, i even swapped the triggerControl to triggerControl12 and no go. driver.find_element_by_css_selector("tr:nth-of-type(1) img[id*='triggerControl'][name='SSLCertModeImg']").click()
I got it, was buried in a iframe i didn't notice. Thanks for your help
This is why it is recommended to post the whole related html in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.