Home > Software design >  RSelenium: Entering search term - trouble with css selector
RSelenium: Entering search term - trouble with css selector

Time:07-26

I am trying to trigger a search on this site. First, I want to enter a search term, then click the search button. I am able to to do the second step, however I am unfortunately unable to access the search field. Below my attempt.

Start RSelenium

link_to_page<-"https://www.cec.ro/sucursale"

library(RSelenium)
rD <- rsDriver(browser = "firefox", port = 483L, verbose = F)
remDr <- rD[["client"]]

# Navigate to site, and wait

remDr$navigate(link_to_page)
Sys.sleep(5)

#Search for element by its id

remDr$findElement(using="css", "#edit-localitate--_jjPr3WukFY")

Error:   Summary: NoSuchElement
         Detail: An element could not be located on the page using the given search parameters.
         class: org.openqa.selenium.NoSuchElementException
         Further Details: run errorDetails method

There is apparently something wrong with the css selector. I checked, it's not nested in an iframe or so, but mabe it's related to the 'form' element it is nested in? Grateful for any hint. Many thanks.

CodePudding user response:

The error is NoSuchElement which indicates an element could not be located on the page using the given search parameter

The second part of the classname i.e. _jjPr3WukFY is dynamically generated and is bound to change sooner/later. They may change next time you access the application afresh or even while next application startup. So can't be used in locators.


Solution

You need to consider any of the other attributes which is static in nature. Example:

remDr$findElement(using="css", "button[id^edit-localitate]")

or

remDr$findElement(using="xpath", "//button[starts-with(@id, 'edit-localitate')]")
  • Related