首页 > 解决方案 > RSelenium,根据文本字符串按下按钮

问题描述

我正在从网站收集一些数据,我需要按一个按钮来打印(并保存)每个对象。为此,我使用 RSelenium。我要导航并单击的是:

<a href="javascript:void(0)" data-bind="clickAndTouch: onClick, blockTouches: true"><span data-bind="attr: { 'class': css() || name() }" aria-hidden="true" class="pri pri-print"></span><em data-bind="text: title()">Print</em></a>

我尝试了几种导航到此的方法,我使用了 XPath,但 XPath 会因不同的搜索而变化。由于我想自动执行此操作并收集更多数据,因此这是行不通的。我相信通过文本“打印”进行导航和单击将是最充分的方式。但是,我还没有找到合适的方法来做到这一点。我试过了:

remote_driver$findElement(using = 'xpath', ("//*[text() = 'Print']"))$clickElement()

但这会导致此错误:

Selenium message: element not interactable
  (Session info: chrome=81.0.4044.92)
  (Driver info: chromedriver=81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044@{#776}),platform=Windows NT 10.0.18363 x86_64)

Error:   Summary: ElementNotVisible
     Detail: An element command could not be completed because the element is not visible on the page.
     Further Details: run errorDetails method

我也尝试过上课但没有成功。我对使用 Selenium 比较陌生,所以希望有人可以给我一个解决方案,并在遇到这些问题时指出一种更好的方法来思考这些问题。

提前致谢!

标签: rseleniumweb-scraping

解决方案


推荐阅读