【问题标题】:R - RSelenium, press Next button & change dropdown options to 25R - R Selenium,按 Next 按钮并将下拉选项更改为 25
【发布时间】:2017-07-28 18:07:21
【问题描述】:

OP 警告:我不太擅长 HTML。

我正在尝试使用 RSelenium 远程驱动器 (browserName='phantomjs') 在需要登录的页面上抓取一些链接。我能够处理登录部分,但是当我尝试提取表中的链接时,我无法抓取所有链接,因为;

1- 表格有 10 行显示的有限视图。这可以使用最多 25 个下拉选项进行更改。

 Things I have tried: 

 option <- remDr$findElement(using = 'xpath', "//*/option[@value = '25']")
 option$clickElement()

 As a result I get the ERROR: Element is hidden

2- 我无法按表格底部的下一步按钮来查看下一页中的链接。

 Similarly, I think I was able to find all 4 buttons using findElement(). But when I run;

 buttons <- remDr$client$findElement("class name", "ag-paging-button")
 nextbutton <- buttons[[3]]
 nextbutton$click()
 nextbutton$clickElement()

然后通过“href”运行链接提取,我得到相同的 10 个链接,就好像什么都没发生一样。

我的问题可以通过完成第 2 部分来解决,但如果我也能得到第一个问题的答案,我将不胜感激。

这是我选定的 HTML 源代码块的样子。

<div class="pxl-aggrid-pagesize">
   "Displaying: "
   
   <select id="pxl-ag-grid-pageSelect">
      <option value="10">10</option>
       <option value="15">15</option>
        <option value="20">20</option>
         <option value="25">25</option>
   </select>
</div>
    
    
    
    
<div class="ag-paging-panel ag-font-style">
   <span class="ag-paging-page-summary-panel">
      <button class="ag-paging-button" ref="btFirst" disabled type="button">First</button>
       <button class="ag-paging-button" ref="btPrevious" disabled type="button">Previous</button>
        "
                 Page "
        <span ref="lbCurrent">1</span>
        " of "
        <span ref="lbTotal">0</span>
        <button class="ag-paging-button" ref="btNext" disabled type="button">Next</button>
         <button class="ag-paging-button" ref="btLast" disabled type="button">Last</button>

【问题讨论】:

    标签: html r rselenium


    【解决方案1】:

    我可以使用 mouseMoveToLocation() 函数来做到这一点。当然,它需要根据网站本身使用的布局进行修改。但是,为了任何好处,它可能会;代码附在下面。

      allButtons <- remDr$client$findElements("xpath", "//button[@class='ag-paging-button']")
        allButtonsText <- sapply(allButtons, function(x)x$getElementText())
        nextButtonNumber <- grep('Next', unlist(allButtonsText))    
    
      remDr$client$mouseMoveToLocation(webElement=allButtons[[nextButtonNumber]])
        remDr$client$click(1)
    

    【讨论】:

      猜你喜欢
      • 2015-08-06
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多