I have one application in which there is one table. I have to find one element there and click on it, and if it is not there it should click on the next page, search the element and click on it. While I am automating it, before clicking only its getting scrolled to the right side and not able to identify the page
//to click on the page number in the bottom
List<WebElement> pages= driver.findElement(By.className("pager")).findElements(By.tagName("a"));
System.out.println(pages.size());
System.out.println(pages.get(0).getText());
System.out.println(pages.get(1).getText());
//list to store the element which I am searching
List<WebElement> ele=driver.findElements(By.xpath("//span[text()='" + wp_id + "']"));
boolean flag=false;
for (int i=1;i<pages.size();i++){
while(!flag){
if (ele.size()>0)
{Thread.sleep(7000);
System.out.println("element is displayed");
driver.findElement(By.xpath("//span[text()='" + wp_id + "']/../..//a[text()='Edit']")).click();
flag = true;
break;
}else{
//to click on the page number
pages.get(i).click();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//span[text()='" + wp_id + "']")));