RSelenium:输入搜索词-css选择器出现问题



我正在尝试触发对此网站的搜索。首先,我想输入一个搜索词,然后单击搜索按钮。我可以执行第二步,但不幸的是,我无法访问搜索字段。低于我的尝试。

启动RSelemium

link_to_page<-"https://www.cec.ro/sucursale"
library(RSelenium)
rD <- rsDriver(browser = "firefox", port = 483L, verbose = F)
remDr <- rD[["client"]]
# Navigate to site, and wait
remDr$navigate(link_to_page)
Sys.sleep(5)
#Search for element by its id
remDr$findElement(using="css", "#edit-localitate--_jjPr3WukFY")
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

css选择器显然有问题。我检查过,它没有嵌套在iframe中,但它可能与嵌套的"form"元素有关?感谢任何提示。非常感谢。

错误为NoSuchElement,表示使用给定的搜索参数无法在页面上找到元素

类名的第二部分,即_jjPr3WukFY是动态生成的,迟早会发生变化。它们可能会在您下次重新访问应用程序时更改,甚至在下次启动应用程序时也会更改。所以不能在定位器中使用。


解决方案

您需要考虑自然界中静态的任何其他属性。示例:

remDr$findElement(using="css", "button[id^edit-localitate]")

remDr$findElement(using="xpath", "//button[starts-with(@id, 'edit-localitate')]")

最新更新