Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Selenium WebDriver的所有页面中搜索元素(分页)_Java_Selenium Webdriver_Junit4 - Fatal编程技术网

Java 在Selenium WebDriver的所有页面中搜索元素(分页)

Java 在Selenium WebDriver的所有页面中搜索元素(分页),java,selenium-webdriver,junit4,Java,Selenium Webdriver,Junit4,我需要在所有页面的表格中搜索特定文本。假设我必须搜索文本(例如:“xxx”),该文本出现在第3页表格的第5行。 我尝试了一些代码: List<WebElement> allrows = table.findElements(By.xpath("//div[@id='table']/table/tbody/tr")); List<WebElement> allpages = driver.findElements(By.xpath("//div[@id='page-navi

我需要在所有页面的表格中搜索特定文本。假设我必须搜索文本(例如:“xxx”),该文本出现在第3页表格的第5行。 我尝试了一些代码:

List<WebElement> allrows = table.findElements(By.xpath("//div[@id='table']/table/tbody/tr"));
List<WebElement> allpages = driver.findElements(By.xpath("//div[@id='page-navigation']//a"));
    System.out.println("Total pages :" +allpages.size());
    for(int i=0; i<=(allpages.size()); i++)
        {
            for(int row=1; row<=allrows.size(); row++)
                {
                    System.out.println("Total rows :" +allrows.size()); 
                    String name = driver.findElement(By.xpath("//div[@id='table']/table/tbody/tr["+row+"]/td[1]")).getText();
                    //System.out.println(name);
                    System.out.println("Row loop");
                    if(name.contains("xxxx"))
                        {
                            WebElement editbutton = table.findElement(By.xpath("//div[@id='table']/table/tbody/tr["+row+"]/td[3]"));
                            editbutton.click();
                            break;
                        }
                    else
                    {
                        System.out.println("Element doesn't exist");
                    }
                    allpages = driver.findElements(By.xpath("//div[@id='page-navigation']//a"));
                }

            allpages = driver.findElements(By.xpath("//div[@id='page-navigation']//a"));
            driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
            allpages.get(i).click();
        }
List allrows=table.findElements(By.xpath(“//div[@id='table']]/table/tbody/tr”);
列出allpages=driver.findElements(By.xpath(“//div[@id='page-navigation']//a”);
System.out.println(“总页数:+allpages.size());

对于(int i=0;i对于每个页面循环,您使用一个table WebElement对象。因此,我假设在进入下一个页面后,您会得到StaleElementReferenceException。我猜解决方案可能是在每个页面循环上定义表。移动此行
List allrows=table.findElements(By.xpath(//div[@id='table']]/table/tbody/tr));
for(inti=0)之后,我们将很难帮助您,除非您发布您在哪里遇到的错误以及HTML的内容看起来像。根据您的更新。异常文本必须告诉您,哪个元素应该被单击。尝试检查它是否“覆盖”了所需的元素。在这里,当它单击editbutton后,它会移动到进一步的代码,即“allpages.get(i).click”,并尝试搜索分页。因此基本上,它不会以“xxx”之后的代码结束埃尔蒙特被发现了