1

I am using RSelenium to scrape content from a website. But when I try to select a radio button it doesn't seem to work.

HTML

<div class="radio">
  <input type="radio" name="sexo" id="sex" value="M">
    <label for="sex">
      <span></span> Hombre
    </label>                                    
  <input type="radio" name="sexo" id="sex1" value="F">
    <label for="sex1">
     <span></span> Mujer
    </label>
</div>

My R code is:

sex <- mybrowser$findElement(using = 'css', '#sex')
sex$clickElement()

But I get the next error:

Error: Summary: ElementNotVisible

Detail: An element command could not be completed because the element is not visible on the page.

class: org.openqa.selenium.ElementNotVisibleException

I have tried using css, xpath, name, id, etc but nothing seems to work.

Thank you for your help.

10
  • Do you see other elements on the page with id="sex"? Commented Apr 5, 2016 at 19:03
  • No, it is the only one. The other id is sex1. Commented Apr 5, 2016 at 19:08
  • What browser are you using? You probably need to resize your browser? Commented Apr 5, 2016 at 19:09
  • Have you tried maximizing the browser window? mybrowser$maxWindowSize() Commented Apr 5, 2016 at 19:10
  • I am using ChromeDriver. I tried maximizing the browser window, but that didn't work. Actually, the radio buttons can be seem in the browser window, regardless of the size of the window. Commented Apr 5, 2016 at 19:14

1 Answer 1

2

I guess the problem here is that you are not choosing the right element to click. You can find the unique selector by going to the website and inspecting the clickable element and then copying the unique selector at the corresponding HTML element. Here it would be .radio > label:nth-child(2), so you can find the element by sex <- mybrowser$findElement(using = "css", ".radio > label:nth-child(2)") and sex$clickElement().

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

1 Comment

Thank you for your help! I didn't know that you could select the label tag.

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.