2

Folks, this is driving me crazy. I have snippets like the following

<label class="" for="M37_Q_POSWECHSEL_BETT_B1">
    <input id="M37_Q_POSWECHSEL_BETT_B1" name="M37_Q_POSWECHSEL_BETT" value="B1" aria-describedby="M37_Q_POSWECHSEL_BETT_error_0" aria-invalid="true" data-clipboard="M37_Q_POSWECHSEL_BETT#B1" type="radio">
    0
</label>

Here, I'd like to select the radio buttons and select them with the following code:

radios = driver.find_elements_by_xpath("//input[starts-with(@id, 'M37_Q_')][@value='B1']")
for radio in radios:
    # just check the id
    print(radio.get_attribute('id'))
    radio.click()

It correctly selects the elements in question. However, it does not get selected nor does it yield any obvious errors. Can we use .click() to select radio buttons here? Is this some kind of handler problem?

Jan
  • 42,290
  • 8
  • 54
  • 79
  • Figure this out Jan? How bout starting a bounty? – zelusp Jul 14 '17 at 20:34
  • Also, how is it possible that my profile has a `reach` that is almost triple yours? I'm not trying to start a pissing match I'm just genuinely curious. Judging by your reputation you should have reached a zillion people by now. – zelusp Jul 14 '17 at 20:42
  • 1
    @zelusp: I guess it's depending on the type of question you're asking. I'd reckon that `JSON` questions are generally reaching a broader audience, e.g. your answer here: https://stackoverflow.com/questions/12943819/how-to-prettyprint-a-json-file/37757378#37757378 – Jan Jul 15 '17 at 06:20

2 Answers2

2

Try this,

driver.execute_script("arguments[0].checked = true;",element)

You can also try by sending ENTER Key to the element.

Chanda Korat
  • 2,453
  • 2
  • 19
  • 23
-2

Try using following Css selector:

        Actions action = new Actions(drive);

        action.moveToElement(drive.findElement( By.cssSelector("label > input[id^='M37_Q_']"))).build().perform();

        drive.findElement( By.cssSelector("label > input[id^='M37_Q_']")).click();
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46