RSelenium - NoSuchElement 即使正在使用 xpath?
RSelenium - NoSuchElement even though xpath is being used?
我正在尝试使用查找元素输入用户名。这是 HTML
更新:已添加站点 - https://riversidescore.com/
<input class="login-input" type="text" placeholder="Username" id="fld_tb_3" tabindex="0" maxlength="128" aria-required="true" aria-labelledby="userLbl" value="">
尽管 id=fld_tb_3 是动态的,并且会在将数据输入字段时发生变化。
这是完整的 xpath
/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input
和 xpath
//*[@id="fld_tb_31"]
我正在尝试使用以下代码,但未找到该元素。我什至尝试使用 class 但没有成功。
Class
remDr$findElement(
using ='xpath', "//div[@class='login-input']/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input"
)
通配符
remDr$findElement(
using ='xpath', "//*[starts-with(@id,'fld_tb_')/div[1]/div/div[1]/div[2]/form/div/div[1]/input"
)
我做错了什么?
添加了错误消息
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
我们可以做到,
#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()
尝试使用用户名的以下 xpath 来识别元素。
//input[@placeholder='Username' and @class='login-input']
因此您的代码将是
remDr$findElement(
using ='xpath', "//input[@placeholder='Username' and @class='login-input']"
)
密码元素的 xpath
//input[@placeholder='Password' and @class='login-input']
登录按钮的 xpath
//input[@value='Sign In' and @class='login-button']
我正在尝试使用查找元素输入用户名。这是 HTML
更新:已添加站点 - https://riversidescore.com/
<input class="login-input" type="text" placeholder="Username" id="fld_tb_3" tabindex="0" maxlength="128" aria-required="true" aria-labelledby="userLbl" value="">
尽管 id=fld_tb_3 是动态的,并且会在将数据输入字段时发生变化。
这是完整的 xpath
/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input
和 xpath
//*[@id="fld_tb_31"]
我正在尝试使用以下代码,但未找到该元素。我什至尝试使用 class 但没有成功。 Class
remDr$findElement(
using ='xpath', "//div[@class='login-input']/html/body/div[1]/div/div[1]/div[2]/form/div/div[1]/input"
)
通配符
remDr$findElement(
using ='xpath', "//*[starts-with(@id,'fld_tb_')/div[1]/div/div[1]/div[2]/form/div/div[1]/input"
)
我做错了什么?
添加了错误消息
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
我们可以做到,
#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()
尝试使用用户名的以下 xpath 来识别元素。
//input[@placeholder='Username' and @class='login-input']
因此您的代码将是
remDr$findElement(
using ='xpath', "//input[@placeholder='Username' and @class='login-input']"
)
密码元素的 xpath
//input[@placeholder='Password' and @class='login-input']
登录按钮的 xpath
//input[@value='Sign In' and @class='login-button']