ulima2_
ulima2_

Reputation: 1336

Find correct CSS tags for r-selenium

I've used this tutorial to learn about RSelenium. It works well for me.

I now tried to use that method on another page (Github), but I'm not sure how to find the CSS tags that focus the mouse on the correct field.

library(RSelenium) 
driver <- rsDriver(browser = "chrome") # start browser
remDr <- driver[["client"]] 

# Go to desired webpage
remDr$navigate("https://github.com/login")

login_id <- remDr$findElement(using = "css",  "login_field")
login_id $sendKeysToElement(list("my_login_name"))

If I use the Selector Gadget, it tells me the tag for the email/username box is #login_field.

If I inspect that part of the webpage, I'm told that the following bits correspond to that box:

<input type="text" name="login" id="login_field" class="form-control input-block" tabindex="1" autocapitalize="off" autocorrect="off" autofocus="autofocus">

But if I run the above code, I get the following error message:

Selenium message:no such element: Unable to locate element: {"method":"css selector","selector":"login_field"}
  (Session info: chrome=69.0.3497.100)
  (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.14393 x86_64)

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

I would appreciate your help how to correctly pick the CSS tags to enter. Thanks!

Upvotes: 0

Views: 905

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193188

To send a character sequence to the Username or email address field on the webpage https://github.com/login you need to induce WebDriverWait and cann use the following CSS_SELECTOR:

input.form-control.input-block#login_field

A Python example:

driver.get("https://github.com/login")
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control.input-block#login_field"))).send_keys('ulima2_')

Browser Snapshot:

Github_Login

Upvotes: 0

kabr
kabr

Reputation: 1339

Besides the legal stuff, it probably works with remDr$findElement(using = "id", value = "login_field"). So using = "id" instead of using = "css"

Upvotes: 1

Related Questions