使用 RSelenium 执行拖放操作

Use RSelenium to perform drag-and-drop action

我想使用 RSelenium 从本网站 http://highereducationstatistics.education.gov.au/. However, before downloading the file, a series of drag-and-drop actions (see this image http://highereducationstatistics.education.gov.au/images/preDragDimension.png) have to be performed so the right dataset could be chosen (See this http://highereducationstatistics.education.gov.au/GettingStarted.aspx 下载文件(通过单击 excel 图片)以获取说明)。

我想知道RSelenium有没有这种拖放功能。我搜索了一整天,猜测 mouseMoveToLocation 与按钮按下功能等其他功能相结合可能是答案,但不知道如何使用它们。有人能帮忙吗?

非常感谢。

首先使用 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/")

然后找到要拖动到 chart/grid 的元素。在此示例中,我将从左侧菜单中选择课程级别。

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

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

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

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

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

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