0

I have been trying to get my script to click on this radio button for 2 days now and nothing I try works.

I have tried, css selector, XPATH, by name, id, using webdriverwait and also switching to Java. Nothing seem to be able to locate it and allow me to click on it. I have no issues with anything else on the website.

What code would you use if you were trying to click on the Radio button ("SearchByParcel")?

HTML code:

<tr>
                    <td style="width:33%;">&nbsp;</td>
                   
                    <td style="text-indent:08px;">
                        <input value="SearchByName" name="SearchRadio" type="radio" id="SearchByName" onclick="ShowMessage(this)" checked="checked">
                        Name
                        &nbsp;<input value="SearchByParcel" name="SearchRadio" type="radio" id="SearchByParcel" onclick="ShowMessage(this)">
                        Parcel #
                        &nbsp;<input value="SearchByAddress" name="SearchRadio" type="radio" id="SearchByAddress" onclick="ShowMessage(this)">
                        Address
                    </td>
                    <td style="width:33%;">&nbsp;</td>
                </tr>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Mason
  • 21
  • 4

2 Answers2

0

To click on the Radio Button associated with the text SearchByParcel you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[value='SearchByParcel']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='SearchByParcel']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I have already tried all of that. Even tried waiting 30 seconds. It still cannot locate it. I tried this page = requests.get("https://radio-form.lilgoomba.repl.co") # Your site here soup = b(page.content, "html.parser") print(soup.find(id="SearchByParcel")); and it gave this back But again no matter how I search it will not find that element to be able to click it. – Mason Mar 10 '23 at 00:45
0

Just check if there is an iframe covering these radio buttons. If yes, first switch into the iframe and then perform click() on the radio buttons. Below code syntax to switch into an iframe for your reference:

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@id='iframe']")))

After switching, try to click() on the desired element by inducing waits

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='SearchByParcel']"))).click()
Shawn
  • 4,064
  • 2
  • 11
  • 23
  • Tried that, it could not locate that way either. – Mason Mar 10 '23 at 00:06
  • So is there an `iframe` wrapping the desired element? What error does it throw? – Shawn Mar 10 '23 at 00:08
  • Not that I can see. But I also tried. – Mason Mar 10 '23 at 00:50
  • I think it has something to do with the Tag label not being properly input. name:null. So it can't locate it. I tried searching by ID, name etc and it cant find any of that info.. . Not sure what else to do, never had this issue. – Mason Mar 10 '23 at 02:14