Home > Blockchain >  Cannot find elements with onclick (R Selenium)
Cannot find elements with onclick (R Selenium)

Time:02-28

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.

CodePudding user response:

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

CodePudding user response:

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']")
    
  • Related