RSelenium和xpaths的新手,尽管有人对这个主题提出了一些问题,但我似乎无法让它对我有用。我正在尝试下载名为"兴趣随时间变化的第一个小部件的CSV文件"。此选项没有唯一的ID /类等,但它是类" widget-actions-item"中的第三个,其中类" widget-actions-item-text"包含" CSV"。
library(RSelenium)
library(wdman)
driver <- rsDriver(browser = "firefox")
remDr <- driver[["client"]]
remDr$open
remDr$navigate("http://trends.google.com/trends/explore?cat=3")
webElem1 <- remDr$findElement("class name", "widget-actions-menu")
webElem1$clickElement()
以上代码翻转打开网页和第一个小部件菜单,其中包含三个下载选项,其中一个是CSV。
webElem2 <- remDr$findElement("xpath", paste0("//div[@class='widget-actions-content']//[@class='widget-actions-item'][3]"))
webElem2$clickElement()
驱动程序无法找到此元素。
<div class="widget-actions-content" ng-show="widgetActions.menuOpen" aria-hidden="false" style="">
<!----><button class="widget-actions-item" ng-if="showActionButton()" ng-click="embed()" title="Embed" track="['Widget', type, 'Embed']" ve-tracking="" jslog="39389; track:generic_click">
<span class="widget-actions-item-icon embed-image flip-rtl"></span>
<div class="widget-actions-item-text">
Embed
</div>
</button><!---->
<!----><button class="widget-actions-item" ng-if="isEditor || share" ng-click="share()" title="Share" track="['Widget', type, 'Share']" ve-tracking="" jslog="39390; track:generic_click">
<span class="widget-actions-item-icon share-image flip-rtl"></span>
<div class="widget-actions-item-text">
Share
</div>
</button><!---->
<!----><button class="widget-actions-item" ng-if="isEditor || (export && showActionButton())" ng-click="export()" title="CSV" track="['Widget', type, 'Export']" ve-tracking="" jslog="39388; track:generic_click">
<span class="widget-actions-item-icon csv-image flip-rtl"></span>
<div class="widget-actions-item-text">
CSV
</div>
</button><!---->
<help-dialog ng-show="!$root.globals.isDesktopMode && helpDialog" class="widget-actions-item ng-hide" show-annotation="true" data="helpDialog" aria-hidden="true"><button class="help-icon-button" ng-click="openDialog()" title="Help">
<i class="material-icons-extended help-icon-color">help_outline</i>
<div class="widget-actions-item-text" ng-show="showAnnotation" aria-hidden="false">
Help
</div>
</button>
</help-dialog>
</div>
答案 0 :(得分:0)
其中任何一个都可行:
//button[contains(.,'CSV')]
//button[div[@class='widget-actions-item-text'][contains(text(),'CSV')]]
//button[div[@class='widget-actions-item-text' and contains(text(),'CSV')]]
//button[@title='CSV']