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?

3
  • Figure this out Jan? How bout starting a bounty? Commented Jul 14, 2017 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. Commented Jul 14, 2017 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: stackoverflow.com/questions/12943819/… Commented Jul 15, 2017 at 6:20

2 Answers 2

2

Try this,

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

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

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

2 Comments

Does not do the job.
@Jan I have gone through some of the articles and they says apply wait because sometimes element is not in the state to click.
-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();

3 Comments

Does not do the job.
As stated, this is in Python, your code is for sth. else (probably JS).
ohh.. my bad, This code is for Java but you can try using selenium actions class in python if available.

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.