遍历frame中的表单:

遍历frame中的表单:

    public void table1() {
        // 查找frame
        List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
        System.out.println("页面上共找到了" + iframes.size() + "  个iframe对象 !!");
        WebElement frame = iframes.get(0);
        // 进入frame
        driver.switchTo().frame(frame);
        // 共计条数和页数对象
        String sumpage = driver.findElement(By.xpath("html/body/div/div/div/section/div/form/div[2]/li[7]/span"))
                .getText();
        System.out.println("===========================" + sumpage + "共计多少页------------------------------------");
        String totalCount = (sumpage.substring(sumpage.indexOf("共") + 1, sumpage.lastIndexOf("条")));
        int totalRecord = Integer.parseInt(totalCount.trim());
        int pageSize = 10;
        int totalPageNum = (totalRecord + pageSize - 1) / pageSize;
        System.out.println(
                "---------------------------------总共有 :" + totalPageNum + "页 !---------------------------------------");
        // 下一页对象;
        WebElement nextPage;
        // WebElement nextPage=
        // driver.findElement(By.xpath("html/body/div/div/div/section/div/form/div[2]/li[6]/a"));
        // System.out.println("==========================已经找到"+nextPage.getText()+"对象!==========================");
        // 查找表单
        /*
         * List<WebElement> tables = driver.findElements(By.tagName("table"));
         * System.out.println("iframes 中共找到了 " + tables.size() + " 个tables !");
         * WebElement table=tables.get(0);
         */
        // 遍历表单
        for (int k = 1; k <= totalPageNum; k++) {
            Log.info("当前是第" + k + " 页!");
            nextPage = driver.findElement(By.xpath("html/body/div/div/div/section/div/form/div[2]/li[6]/a"));
            List<WebElement> tables = driver.findElements(By.tagName("table"));
            System.out.println("iframes 中共找到了 " + tables.size() + " 个tables !");
            WebElement table = tables.get(0);
            List<WebElement> rows = table.findElements(By.tagName("tr"));
            for (WebElement row : rows) {
                List<WebElement> cols = row.findElements(By.tagName("td"));
                for (WebElement col : cols) {
                    System.out.print("|");
                    System.out.print(col.getText() + "    |");
                }
                System.out.println("");
            }
            nextPage.click();
            // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            OpenBrowserInfo.ThreadSleep();
        }

        // return null;
    }
View Code

 

posted @ 2017-03-11 16:38  linbo.yang  阅读(126)  评论(0编辑  收藏  举报