Home > Enterprise >  Error using findElement function in RSelenium. Struggling to select a text box and type into it
Error using findElement function in RSelenium. Struggling to select a text box and type into it

Time:01-10

I'm an RSelenium rookie trying to log in to a website. I've used the following code:

remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "chrome")
remDr$open()
remDr$navigate("https://trakcarelabwebview.nhls.ac.za/trakcarelab/csp/system.Home.cls#/Component/SSUser.Logon")

remDr$screenshot(display = TRUE) # Just checking that I'm reaching the site

webElem <- remDr$findElement(using = 'name', value = "USERNAME")
webElem$sendKeysToElement(list("my_username"))

This throws an error: Error in resContent[["status"]] : subscript out of bounds.

I've tried to find the element with using = class, xpath, and css selector (I used Selector Gadget to find the value for this). I've tried selecting other elements on the page, and all throw the same error when I try to interact with them.

What am I doing wrong? If possible, I'd like to type in a username, password, and click the logon button. Please help me out.

CodePudding user response:

You can use simply use xpath

Input USERNAME

remDr$findElement('xpath', '//*[@id="SSUser_Logon_0-item-USERNAME"]')$sendKeysToElement(list("myusername"))

Input PASSWORD

remDr$findElement('xpath', '//*[@id="SSUser_Logon_0-item-PASSWORD"]')$sendKeysToElement(list("password"))

Click logon

remDr$findElement('xpath', '//*[@id="SSUser_Logon_0-button-Logon"]/span')$clickElement()
  •  Tags:  
  • Related