I'm trying to use find element to enter a username. This is the HTML
UPDATED: Added site - https://riversidescore.com/
<input type="text" placeholder="Username" id="fld_tb_3" tabindex="0" maxlength="128" aria-required="true" aria-labelledby="userLbl" value="">
Although that id=fld_tb_3 is dynamic and changes when data is entered into the field.
This is the full xpath
/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input
And the xpath
//*[@id="fld_tb_31"]
I am trying to use the following code but the element is not being found. I even tried using the class to no luck. Class
remDr$findElement(
using ='xpath', "//div[@class='login-input']/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input"
)
Wildcard
remDr$findElement(
using ='xpath', "//*[starts-with(@id,'fld_tb_')/div[1]/div/div[1]/div[2]/form/div/div[1]/input"
)
What am I doing wrong?
Added Error Message
Selenium message:{"errorMessage":"Unable to find element with xpath '//*[@id=\"fld_tb_3\"]'","request":{"headers":{"Accept":"application/json, text/xml, application/xml, */*","Accept-Encoding":"deflate, gzip, br","Content-Length":"49","Content-Type":"application/json","Host":"localhost:4444","User-Agent":"libcurl/7.61.1 r-curl/4.3.2 httr/1.4.2"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//*[@id=\\\"fld_tb_3\\\"]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/b128fad0-ac65-11ec-ae40-d37036d5ead6/element"}}
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
CodePudding user response:
We can do,
#enter username
user <- remDr$findElement(using = 'xpath', value = '/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input')
user$sendKeysToElement(list("my_username"))
#enter passowrd (has to use full xpath)
pass <- remDr$findElement(using = 'xpath', value = '/html/body/div[1]/div/div[1]/div[2]/form/div/div[4]/input')
pass$sendKeysToElement(list("my_password"))
#click on login
remDr$findElement(using = "xpath",'//*[@id="root"]/div/div[1]/div[2]/form/div/input')$clickElement()
CodePudding user response:
Try to identify the element with following xpath for username.
//input[@placeholder='Username' and @class='login-input']
so your code will be
remDr$findElement(
using ='xpath', "//input[@placeholder='Username' and @class='login-input']"
)
xpath for password element
//input[@placeholder='Password' and @class='login-input']
xpath for sign in button
//input[@value='Sign In' and @class='login-button']