简体   繁体   English

RSelenium单选按钮不可单击

[英]RSelenium radio button not clickable

I am using RSelenium to scrape content from a website. 我正在使用RSelenium从网站上抓取内容。 But when I try to select a radio button it doesn't seem to work. 但是,当我尝试选择单选按钮时,它似乎不起作用。

HTML 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: 我的R代码是:

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

But I get the next error: 但是我得到了下一个错误:

Error: Summary: ElementNotVisible 错误:摘要:ElementNotVisible

Detail: An element command could not be completed because the element is not visible on the page. 详细信息:元素命令无法完成,因为该元素在页面上不可见。

class: org.openqa.selenium.ElementNotVisibleException 类:org.openqa.selenium.ElementNotVisibleException

I have tried using css, xpath, name, id, etc but nothing seems to work. 我试过使用CSS,XPath,名称,ID等,但是似乎没有任何效果。

Thank you for your help. 谢谢您的帮助。

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. 您可以通过访问网站并检查clickable元素,然后将唯一选择器复制到相应的HTML元素来找到唯一选择器。 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() . 这里是.radio > label:nth-child(2) ,因此您可以按sex <- mybrowser$findElement(using = "css", ".radio > label:nth-child(2)")查找元素sex <- mybrowser$findElement(using = "css", ".radio > label:nth-child(2)")sex$clickElement()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM