library(xml2)
library(rvest)
require(RSelenium)
# open the remote driver
fprof <- makeFirefoxProfile(list(browser.download.dir = "C:/temp"
, browser.download.folderList = 2L
, browser.download.manager.showWhenStarting = FALSE
, browser.helperApps.neverAsk.saveToDisk = "application/zip"))
remDr <- remoteDriver(browserName = "firefox",remoteServerAddr = "192.168.99.100",port = 4445L,extraCapabilities = fprof)
remDr$open(silent = TRUE)
#
# go to the webpage
remDr$navigate("https://www.expedia.co.uk/Shanghai-Hotels-Fairmont-Peace-Hotel.h44282.Hotel-Information")
#close popup window
remDr$screenshot(display = TRUE)
closebt <- remDr$findElement(using = "id", "modalCloseButton")
closebt$clickElement()
remDr$screenshot(display = TRUE)# just to see if the popup windows is closed
# create R objects from the website elements
guestreview <- remDr$findElement(using = 'id', value = "tab-reviews")
# click the guest review button
guestreview$clickElement()
# Let us read the html page now and extract the links of the various articles loaded
#
# get the page html
#
page_source<-remDr$getPageSource()
#load first 10 review
reviews <- read_html(page_source[[1]]) %>%
html_nodes(xpath = '//*[contains(concat( " ", @class, " " ), concat( " ", "translate-text", " " ))]') %>%
html_text()
reviews
remDr$screenshot(display = TRUE)
#load next page
Nextbtn <- remDr$findElement(using = 'xpath', '//*[contains(concat( " ", @class, " " ), concat( " ", "pagination-next", " " ))] | //abbr')
Nextbtn$clickElement()
remDr$screenshot(display = TRUE)
remDr$close()
大家好。我需要帮助来解决我的问题。我想点击旁边的按钮,废弃更多用户评论。但问题是我收到此错误消息:
Selenium消息:元素在点
时无法点击
没有弹出窗口或警报,当我制作
时remDr $ screenshot(display = TRUE)
我可以看到按钮在那里,所以它没有被隐藏。 我正在使用selenium / standalone-firefox:2.53.0图片 你能帮我么?我不知道我做错了什么
答案 0 :(得分:2)
#load next page
#click on next
#remDr$findElement(using = 'class', "pagination-next")$clickElement()
remDr$executeScript("arguments[0].click();"
, list(remDr$findElement("class", "pagination-next")))
remDr$screenshot(display = TRUE)
&#13;
我终于找到了错误。有一个导航栏覆盖了我想要点击的元素。 这就是我收到错误的原因 由于另一个元素会收到点击,因此元素无法点击 要根据此链接解决这个问题,我使用JavaScript来点击元素。和宾果,它对我有用 RSelenium and Javascript