mks212
mks212

Reputation: 921

Unable To Fill Form Using RSelenium, Unable To Locate Element

I am trying to fill in a login form.

Here is the code to reproduce the error:

library(RSelenium)
require(XML)

RSelenium::startServer()
remDr <<- remoteDriver()
remDr$open()

appURL <- "https://www.schwab.com/public/schwab/nn/login/login.html&lang=en"
remDr$navigate(appURL)

remDr$findElement("id", "LoginId")$sendKeysToElement(list("username"))

This is the error message received: Selenium message:Unable to locate element: #LoginId

I have tried using xpath and css with the same result. I believe the issue has to do with the page using frames, so remDr cannot "see" the login box.

I then run this code:

webElem <- remDr$findElements(value = "//iframe")
sapply(webElem, function(x){x$getElementAttribute('name')})
[[1]]
[1] "loginIframe"

[[2]]
[1] ""


remDr$switchToFrame(1)
remDr$findElement("id", "LoginId")$sendKeysToElement(list("username"))

The same error message is received: Selenium message:Unable to locate element: #LoginId

Any suggestion on how to get the remote browser to locate the login box?

Thank you.

Upvotes: 0

Views: 1229

Answers (1)

TTR
TTR

Reputation: 129

You're right - it's an issue with the frames. The below code worked for me.

iframe <- remDr$findElement("xpath", "*//iframe[@id = 'loginIframe']")
remDr$switchToFrame(iframe)
remDr$findElement("id", "LoginId")$sendKeysToElement(list("username"))

Upvotes: 2

Related Questions