0

I am trying to use RSelenium to navigate this page: https://championsleague.len.eu/calendar/

For some reason, I can't seem to be able to find any element on the page. Firstly, the selector gadget does not work on it.

In addition, when I use the developer tools to grab the class or xpath of an object that I want to click (for example, let's say I want on the DAY 10 button of the calendar), the findElements function always returns an empty list.

remDr$navigate("https://championsleague.len.eu/calendar")

#using CSS selector
remDr$findElements("css selector", '#tblBottoniDay > div')

#using xpath
remDr$findElements("xpath", '//*[@id="tblBottoniDay"]/div')

Does anyone have an idea of what I can do to solve this problem?

Thank you very much.

Nad Pat
  • 3,129
  • 3
  • 10
  • 20
Andrew
  • 1
  • 1

3 Answers3

0

The element with text as DAY 10 is within an <frame> so you have to switchToFrame and you can use the following Locator Strategies:

  • Using xpath:

    webElem <- remDr$findElement(using = "id", value = "advanced_iframe")
    remDr$switchToFrame(webElem$elementId)
    remDr$findElement("xpath", "//span[text()='DAY 10']")
    

References

Package ‘RSelenium’

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi and thanks for the help. Unfortunately, I get an error when I execute the 2nd line: Selenium message:The given selector frame#0,iframe#0 is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: An invalid or illegal selector was specified. Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03' System info: host: 'f275099dc6f5', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.16.3-microsoft-standard-WSL2', java.version: '1.8.0_91' Driver info: driver.version: unknown – Andrew Feb 28 '22 at 08:33
  • Well, I'm sorry I don't extensively code in R Selenium, however the idea remains the same. See _**Page 14**_ of [Package ‘RSelenium’](https://cran.r-project.org/web/packages/RSelenium/RSelenium.pdf) – undetected Selenium Feb 28 '22 at 08:38
0

You are missing a delay here.
Before accessing element on the page you need to wait for these elements to be completely loaded.
The simplest way is to add a delay there, like this:

remDr$navigate("https://championsleague.len.eu/calendar")

Sys.sleep(5)

remDr$findElements("css selector", '#tblBottoniDay > div')

The more preferred way is to use Expected Conditions to wait for elements visibility

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • 1
    I executed your code but I still get an empty list... I have a weak internet connection at my house. Do you think this might explain my problem? Also, did it work for you? Did you actually get the elements back as an output? Thanks so much – Andrew Feb 27 '22 at 18:07
  • No, I didn't try that. I know Selenium, but never used it with R language. 2 questions that may be useful: 1) Have you tried to put longer pause? In case of slow internet connection you possibly will need more time to wait. 2) Maybe you missing extracting the texts from the received web elements? – Prophet Feb 27 '22 at 20:04
0

The item(DAY) you want to click is in iframe first we shall swtich to iframe and use fullxpath to click the item.

#launch browser
library(RSelenium)
driver <- rsDriver(browser = "chrome")

remDr<-driver[["client"]]
url = "https://championsleague.len.eu/calendar"
#navigate
remDr$navigate(url)

#accept cookie
remDr$findElement(using = "xpath",'//*[@id="cmplz-cookiebanner-container"]/div/div[6]/button[1]')$clickElement()
#swtich to iframe
webElem <- remDr$findElements(using = "xpath", value = ' //*[@id="advanced_iframe"]')
 remDr$switchToFrame(webElem[[1]])
#now we shall click on DAY12
 remDr$findElement(using = "xpath",'/html/body/div[1]/div[1]/div/div/div/div[2]/div/div[2]/div[12]/div/span')$clickElement()
#note that last number in xpath represents the day 

enter image description here

Nad Pat
  • 3,129
  • 3
  • 10
  • 20