KTaiga933
KTaiga933

Reputation: 1

Selenium Python: Clicking on radio button that is not an input radio

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>

Upvotes: 0

Views: 45

Answers (2)

vitaliis
vitaliis

Reputation: 4212

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.

Upvotes: 1

Prophet
Prophet

Reputation: 33361

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"]

Upvotes: 1

Related Questions