Sunday, 7 July 2019

Rselenium can not click all radiobutton (only some of them)

I am trying to get some scraping skills with RSelenium and I am confronted to a difficulty.

I want to choose languages for the comments in this page. But when the popup radio button list appear, I manage to click some of them and not the others. I thing I did get the elements properly though. Here is what I tried

library(RSelenium)

remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  port = 4445L,
  browserName = "firefox"
)

url <- "https://www.tripadvisor.com/Restaurant_Review-g187438-d12718258-Reviews-Prohobitox-Malaga_Costa_del_Sol_Province_of_Malaga_Andalucia.html"

remDr$navigate(url)

# click more language popup
webElems <- remDr$findElements(using = "css selector", ".taLnk") # taLnk is for dropdown like
webElemstext <- unlist(lapply(webElems, function(x) {x$getElementText()}))
webElems[[which(webElemstext == "More languages")]]$clickElement() 

enter image description here

I try to get the radio buttons this way:

langues <- remDr$findElements(using = "class", "ui_radio")
langues_txt <-  unlist(lapply(langues, function(x) {x$getElementText()}))

> langues_txt
 [1] "All languages"  "English (120)"  "Spanish (66)"   "Norwegian (25)" "All languages" 
 [6] "English (120)"  "Spanish (66)"   "Norwegian (25)" "Dutch (22)"     "Swedish (13)"  
[11] "French (12)"    "German (10)"    "Italian (7)"    "Danish (3)"     "Finnish (2)"   
[16] "Portuguese (1)"

The weird thing is that I can click the last radiobutton, but not the others, and I don't get it. If I do try to click finnish:

langues[[14]]$clickElement() 
remDr$screenshot(display = TRUE)

enter image description here

nothing happend. But with Portuguese:

langues[[16]]$clickElement() 
remDr$screenshot(display = TRUE)

enter image description here

Here it worked. I don't see any difference between the two situation, so I don't find a solution to click any radio button in the popup.

Any idea ?



from Rselenium can not click all radiobutton (only some of them)

No comments:

Post a Comment