j9208
j9208

Reputation: 15

RSelenium radio button not clickable

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.

Upvotes: 1

Views: 535

Answers (1)

akuiper
akuiper

Reputation: 214917

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().

Upvotes: 2

Related Questions