简体   繁体   English

如何利用通过 Rselenium 中的 find“findelements”命令找到的元素?

[英]How to utilize an element found via the find "findelements" command in Rselenium?

I'm trying to select a certain checkbox using the link below.我正在尝试使用下面的链接选择某个复选框。 I've managed to find the checkbox using the findelements command, however the problem is that I can't actually use the elements I found with the findelements command to click on an element.我已经设法使用findelements命令找到了复选框,但是问题是我实际上无法使用通过findelements命令找到的元素来单击元素。 The problem seems to be that the findelements command outputs a list which is unusable if you unlist it as a character, as it loses its "object containing active binding" schtick.问题似乎是findelements命令输出一个列表,如果您unlist其作为字符unlist列出,该列表将无法使用,因为它会丢失其“包含活动绑定的对象”schtick。

I don't really know what to make of this and how to solve it, but it should be relatively easy, I can't imagine that it would be impossible to interact with an element found in a findelements list, but every attempt, including something as simple as "elements[4]" doesn't seem to work.我真的不知道该怎么做以及如何解决它,但它应该相对容易,我无法想象与findelements列表中找到的元素进行交互是不可能的,但是每次尝试,包括像“元素[4]”这样简单的东西似乎不起作用。

remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost",
                                 port = 4445L,
                                 browserName = "chrome")
remDr$open()
remDr$navigate("http://chicagodemocracy.org/ChooseElection.jsp")
remDr$screenshot(display = TRUE)

elements<- remDr$findElements(using = 'name', "office")
checkbox<-elements[4]
checkbox$clickElement()

remDr$screenshot(display = TRUE)
html <- xml2::read_html(remDr$getPageSource()[[1]])

Try using xpath to find the elements directly.尝试使用 xpath 直接查找元素。 You can the 'value' depends on which checkbox you like to select您可以选择“值”取决于您喜欢选择哪个复选框

checkbox<- remDr$findElement(using = 'xpath', "//li/input[@value='Alderman']")

checkbox$clickElement()

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

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