RSelenium - 使用 xpath 选择父元素

RSelenium - selecting parent element with xpath

我正在尝试使用 RSelenium 通过按钮捕获网页上可用的 csv。相关的 html 是:

<a ng-click='download()'><i class='csv-download'></i> Download</a>

我可以 select i 元素通过它的 class 与:

remDr$findElement(using = 'css selector', ".csv-download")

我认为要使按钮推送自动化,我需要 select 父 a 元素,但不知道如何执行此操作。 xpath 似乎是最好的方法:

remDr$findElement(using = 'xpath', "//i[@class='csv-download']/parent::*")
Error:   Summary: NoSuchElement
     Detail: An element could not be located on the page using the given search parameters.
     class: org.openqa.selenium.NoSuchElementException

肯定是xpath公式有问题。感谢您的帮助。

您可以继续使用 CSS 选择器并依赖 ng-click 属性:

remDr$findElement(using = 'css selector', "a[ng-click*=download]")

其中 *= 表示 "contains"。


但是,要回答您的问题,请使用 ..:

remDr$findElement(using = 'xpath', "//i[@class='csv-download']/..")