【问题标题】:Use RSelenium to perform drag-and-drop action使用 RSelenium 执行拖放操作
【发布时间】:2018-08-04 19:58:08
【问题描述】:

我想使用 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】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      • 1970-01-01
      • 2020-07-27
      • 2010-11-05
      • 1970-01-01
      相关资源
      最近更新 更多