Entering a site using RSelenium & phantomjs in R, there are several instances of the class

I am trying to access this page: https://www.optionslam.com/accounts/login/ , using the code on this post as a starting point, Clear the website with password protection in R

I was able to fill in the login fields, but I can’t click the login button. If you look at the source of the page, the login class is the "red button"

<input type="submit" value="Log in" class="red-button"/> 

However, at the top of the page there is another form that also uses the same class, and clicks the clickElement () button on it. Reading the RSelenium documentation, I cannot find a way to search for a second instance of this class or search for it based on type = "submit" or value = "Log In".

Here is my code:

 library(RSelenium) pJS <- phantom() # start phantomjs appURL <- 'https://www.optionslam.com/accounts/login/' remDr <- remoteDriver(browserName = "phantomjs") remDr$open() remDr$navigate(appURL) remDr$findElement("id", "id_username")$sendKeysToElement(list("user")) remDr$findElement("id", "id_password")$sendKeysToElement(list("pass")) remDr$findElement("class name", "red-button")$clickElement() 

Thank you for your help.

+2
source share
1 answer

Two options:

Use findElements to get both buttons and click on the second:

 remDr$findElements("class name", "red-button")[[2]]$clickElement() 

or use a different selection method, as @SymbolixAU offers and targets the second element directly:

 webElem <- remDr$findElement("css", ".red-button[value='Log in']") webElem$getElementAttribute("outerHTML") #[[1]] #[1] "<input type=\"submit\" value=\"Log in\" class=\"red-button\">" webElem$clearElement() 
+1
source

Source: https://habr.com/ru/post/1011609/


All Articles