单击带有 RSelenium 的复选框
Click checkbox with RSelenium
我想点击这个 url 上的复选框 'HIV/AIDS':https://www.unodc.org/ngo/showExtendedSearch.do
使用 RSelenium
到目前为止,这是我的代码:
#load library
library(RSelenium)
#Check for serves and start server
RSelenium::checkForServer()
RSelenium::startServer()
#Specify remote driver
remDr <- RSelenium::remoteDriver(browserName='firefox')
#new remotedriver using default initialisation values
remoteDriver$new()
#Initialise session
remDr$open()
#navigate to advanced search page
url <- "https://www.unodc.org/ngo/showExtendedSearch.do"
remDr$navigate(url)
#Click 'HIV/AIDS' filter
button <- remDr$findElements("name","HIV/Aids")
button$clickElement()
查找复选框元素时出错'HIV/AIDS'。我现在在 return 中得到一个空列表。我尝试使用 selectorgadget 导致以下代码:
button <- remDr$findElements("css selector",'#applicationArea > form > table > tbody > tr > td > table:nth-child(7) > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td:nth-child(4) > input[type="checkbox"]')
button$clickElement()
这次没有得到空列表,也没有得到想要的webelement
如果有人能提供帮助,那将非常有帮助。
编辑:我最后的代码(使用 css 选择器)似乎对其他人也有效。但是,我收到以下错误:attempt to apply non-function
,所以一定是其他地方出了问题。
试试这个:
button <- remDr$findElements("name","areaAidshiv")
button$clickElement()
你得到的代码对我有效:
library(RSelenium)
remDr <- remoteDriver(browserName = "firefox")
remDr$open()
url <- "https://www.unodc.org/ngo/showExtendedSearch.do"
remDr$navigate(url)
webElem <- remDr$findElement(using = 'css',
value = '#applicationArea > form > table > tbody > tr > td > table:nth-child(7) > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td:nth-child(4) > input[type="checkbox"]')
webElem$clickElement()
我想点击这个 url 上的复选框 'HIV/AIDS':https://www.unodc.org/ngo/showExtendedSearch.do
使用 RSelenium
到目前为止,这是我的代码:
#load library
library(RSelenium)
#Check for serves and start server
RSelenium::checkForServer()
RSelenium::startServer()
#Specify remote driver
remDr <- RSelenium::remoteDriver(browserName='firefox')
#new remotedriver using default initialisation values
remoteDriver$new()
#Initialise session
remDr$open()
#navigate to advanced search page
url <- "https://www.unodc.org/ngo/showExtendedSearch.do"
remDr$navigate(url)
#Click 'HIV/AIDS' filter
button <- remDr$findElements("name","HIV/Aids")
button$clickElement()
查找复选框元素时出错'HIV/AIDS'。我现在在 return 中得到一个空列表。我尝试使用 selectorgadget 导致以下代码:
button <- remDr$findElements("css selector",'#applicationArea > form > table > tbody > tr > td > table:nth-child(7) > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td:nth-child(4) > input[type="checkbox"]')
button$clickElement()
这次没有得到空列表,也没有得到想要的webelement
如果有人能提供帮助,那将非常有帮助。
编辑:我最后的代码(使用 css 选择器)似乎对其他人也有效。但是,我收到以下错误:attempt to apply non-function
,所以一定是其他地方出了问题。
试试这个:
button <- remDr$findElements("name","areaAidshiv")
button$clickElement()
你得到的代码对我有效:
library(RSelenium)
remDr <- remoteDriver(browserName = "firefox")
remDr$open()
url <- "https://www.unodc.org/ngo/showExtendedSearch.do"
remDr$navigate(url)
webElem <- remDr$findElement(using = 'css',
value = '#applicationArea > form > table > tbody > tr > td > table:nth-child(7) > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td:nth-child(4) > input[type="checkbox"]')
webElem$clickElement()