我正在尝试使用 RSelenium 通过按钮捕获网页上可用的 csv。相关html为:
<a ng-click='download()'><i class='csv-download'></i> Download</a>
我可以通过它的类选择 i
元素:
remDr$findElement(using = 'css selector', ".csv-download")
我认为要自动执行按钮推送,我需要选择父 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]")
其中 *=
表示“包含”。
但是,要回答您所问的问题,请使用..
:
remDr$findElement(using = 'xpath', "//i[@class='csv-download']/..")
关于RSelenium - 使用 xpath 选择父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36064764/