使用RSelenium执行拖放操作

问题描述 投票:0回答:1

我想使用RSelenium从这个网站http://highereducationstatistics.education.gov.au/下载文件(通过点击excel图像)。但是,在下载文件之前,必须执行一系列拖放操作(请参阅此图像http://highereducationstatistics.education.gov.au/images/preDragDimension.png),以便选择正确的数据集(有关说明,请参阅此http://highereducationstatistics.education.gov.au/GettingStarted.aspx)。

我想知道RSelenium是否具有这种类型的拖放功能。我已经搜索了这一整天并猜测mouseMoveToLocation与其他函数(如buttondown函数)结合可能是答案,但不知道如何使用它们。有人能帮忙吗?

非常感谢。

r web-scraping rselenium
1个回答
0
投票

首先使用RSelenium导航到页面:

library(RSelenium)
rD <- rsDriver() # runs a chrome browser, wait for necessary files to download
remDr <- rD$client
remDr$navigate("http://highereducationstatistics.education.gov.au/")

然后找到要拖动到图表/网格的元素。在本例中,我将从左侧菜单中选择“课程级别”。

webElem1 <- remDr$findElement('xpath', "//span[@title = 'Course Level']")

选择要放置此菜单项的元素。在这种情况下,元素有一个id = "olapClientGridXrowHeader"

webElem2 <- remDr$findElement(using = 'id', "olapClientGridXrowHeader")

选择两个项目后,将第一个项目拖动到第二个项目中,如下所示:

remDr$mouseMoveToLocation(webElement = webElem1)
remDr$buttondown()
remDr$mouseMoveToLocation(webElement = webElem2)
remDr$buttonup()

请注意,这些方法适用于远程驱动程序,而不是元素。

© www.soinside.com 2019 - 2024. All rights reserved.