Stale Object Reference while Navigation using Selenium

后端 未结 3 1117
攒了一身酷
攒了一身酷 2021-01-26 12:16

I have been trying a simple program that navigates and fetches data from the new page, comes back in history and open other page and fetch data and so on until all the links hav

3条回答
  •  走了就别回头了
    2021-01-26 12:36

    Please check this code

       private void extractText() {
            try {
                List rows = driver.findElements(By.xpath("//*[@id='gvSearchResults']/tbody/tr"));
                List links = null;
                System.out.println(rows.size());
                for (int i = 0; i < rows.size(); i++) {
                    links = driver.findElements(By.xpath("//*[@id='gvSearchResults']/tbody/tr/td[1]/a"));
                    WebElement ele= links.get(0);
                    System.out.println(ele.getText() + ", ");
                    ele.click();
                    System.out.println("After click");
                    driver.findElement(By.id("ctl00_MainContent_btnBack")).click();                     
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

提交回复
热议问题