简体   繁体   English

java selenium-导航到分页表上未显示的页码

[英]java selenium - Nav to a page number not shown on a Paginated Table

Background 背景

I have a Selenium script in java that performs a search and the result are in a paginated table. 我在Java中有一个Selenium脚本来执行搜索,结果在分页表中。 The table nav at the bottom is: 底部的导航栏是:

[‹‹ First] [‹ Prev] [1] [2] [3] [4] [5] [Next ›] [Last ››] [‹‹第一] [‹上一个] [1] [2] [3] [4] [5] [下一个›] [最后››]

In some cases, my search will return 100s of thousands of records which would give me 10s of thousands of pages. 在某些情况下,我的搜索将返回数十万条记录,这将使我获得数十万条页面。

Issue 问题

My Issue is, when I run the script, if it stops or crashes in the middle for what ever reason. 我的问题是,当我运行脚本时,如果脚本由于某种原因停止或在中间崩溃。 The next time I run the script, it has to go through all the pages that I had previously searched, to get back to where it left off. 下次运行脚本时,它必须遍历以前搜索过的所有页面,以返回到上一页。 So my script will look at row 'X' and see if I already looked at that record, skip it if I checked in a previous run or do what it needs to if I had not checked it. 因此,我的脚本将查看“ X”行,看看我是否已经查看了该记录,如果我在以前的运行中签入,则跳过该记录,或者如果我没有检查它,则执行所需的操作。 After all rows of page number 'Y' are complete, go to the next page. 页码“ Y”的所有行均完成后,请转到下一页。 This takes too long when I need to go all the way back to a page that's a high number. 当我需要一直返回到大量页面时,这花费了太长时间。

Url does not have any page info in it and does not change. 网址中没有任何页面信息,并且不会更改。 Stays at ....resultTable.html. 保持在.... resultTable.html。

The page does not have a "Go to Page: [ ]" input field to jump to a page. 该页面没有“转到页面:[]”输入字段以跳转到页面。 And, we cannot add it. 而且,我们无法添加它。

Solution? 解?

I was thinking, if there is a way I can just navigate to a requested page, maybe with javascript? 我在想,是否有一种方法可以导航到请求的页面,也许可以使用javascript? Because the table's navigation bar does not allow you to jump to a page. 因为表格的导航栏不允许您跳至页面。 I would perform my search and on page 1 I would check what ever page my last run got to and navigate to that page. 我将执行搜索,在第1页上,我将检查上次运行的页面,然后导航到该页面。 That way my script does not need to go through every page 1 by 1, checking each row if that is a record I already checked.... (I am technicaly weak in this area, need your help 🙂) 这样,我的脚本就不需要一一遍遍地检查每一行,如果那是我已经检查过的记录……。(我在这方面技术上很薄弱,需要您的帮助🙂)

This is the onClick="" code on the table nav: 这是导航栏上的onClick =“”代码:

<a href="#" 
   onclick="mojarra.jsfcljs(
      document.getElementById('idHere'), 
      {'j_idt##:#:j_idt##':'j_idt##:#:j_idt##', 
      'pageIndex':'',
      'moveToPageNum':'##'},
      '');return false"
>##</a>

I wonder if I can just send javaScript code with the requested page I need in the 'moveToPageNum':'##' section? 我想知道是否可以仅在'moveToPageNum':'##'部分中使用所需的请求页面发送javaScript代码?

In my script, at some point I use JavascriptExecutor to perform a task, maybe I can use it for the purposes described above? 在我的脚本中,有时会使用JavascriptExecutor执行任务,也许可以将其用于上述目的? Example of how I use it in a different place in my script: 我如何在脚本的其他位置使用它的示例:

public static void openNewTab(WebDriver driver, String url) { 
   ((JavascriptExecutor) driver).executeScript("window.open('" + url + " ','_blank');");
   changeTab(driver, url);
}

Well, After a lot of editing my question, and I'm sure people opening the question and being like "I have to read all this...". 好吧,经过大量编辑我的问题之后,我确定人们会打开问题并像“我必须阅读所有这些...”。 I got it, sorry 😞. 我明白了,对不起😞。

I made a method that executes java script: 我做了一个执行Java脚本的方法:

public static void goToPage(WebDriver driver, int page) {

    ((JavascriptExecutor) driver)
            .executeScript("mojarra.jsfcljs(document.getElementById('idHere'),"
                           + "{'j_idt##:#:j_idt##':'j_idt##:#:j_idt##','pageIndex':'',"
                           + "'moveToPageNum':'" + page + "'}," + "'');return false");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM