【问题标题】:Press a button based on action根据动作按下按钮
【发布时间】:2023-03-28 21:45:02
【问题描述】:

我想按下按钮标签中包含此选项的按钮:

<div aria-controllers="my-list"> Press for more information </div>

我应该使用来自 R selenium 的哪个调用?

这是我尝试过的:

webElem1 <- remDr$findElement(using = 'aria-controllers', value = 'my-list')
webElem1$sendKeysToElement(list('R', key = 'enter'))

如果我使用它,我会收到以下错误:

webElem <- remDr$findElement(using = 'aria-controllers', value = "my-list")
Error in match.arg(using) : 
  'arg' should be one of “xpath”, “css selector”, “id”, “name”, “tag name”, “class name”, “link text”, “partial link text”

【问题讨论】:

  • 任何帮助,请问我该怎么办?

标签: r selenium rselenium


【解决方案1】:

我不知道 R 但我认为你需要的是

webElem1 <- remDr$findElement(using = 'css selector', value = 'div[aria-controllers="my-list"]')

第一个参数是定位器的类型,这就是为什么列出所有定位器类型(如“id”、“css 选择器”等)时出现错误的原因。我选择了一个 CSS 选择器,因为我认为它最符合你的方式试图定位元素。

第二个参数是定位器本身。在这种情况下,CSS 选择器。

您可能应该花一些时间查看文档。

https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-basics.html#search-using-css-selectors

https://www.rdocumentation.org/packages/seleniumPipes/versions/0.3.7/topics/findElement

【讨论】:

  • 谢谢。我尝试了您的建议,但收到此错误:Error: Summary: NoSuchElement Detail: An element could not be located on the page using the given search parameters.
  • 由于我看不到页面,您必须查看并了解原因。检查IFRAME 或添加等待,看看是否有帮助。
猜你喜欢
  • 2021-05-25
  • 2018-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多