0

I have a list of links and wants to scroll to a new link each time loop iterates. only one link is visible on the current view. is it possible to scroll through a list of web elements or not?

this is the URL link -- https://www.caknowledgeclub.com/caauditfirms

i want to get data from each more link for which i need to scroll to every more link but unable to so far.

package fetchingData;

import java.io.IOException;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class Base extends TestBase
{   
    @FindBy(xpath="//div[@class='col-md-12 align-bottom']/div[7]/ul/li[1]")
    WebElement ownerName;
    @FindBy(xpath="//div[@class='col-md-12 align-bottom']/div[7]/ul/li[2]")
    WebElement ofcAddress;  
    @FindBy(xpath="//div[@class='col-md-12 align-bottom']/div[7]/ul/li[3]")
    WebElement email;   
    @FindBy(xpath="//div[@class='col-md-12 align-bottom']/div[7]/ul/li[4]")
    WebElement contactNum;  
    @FindBy(xpath="//div[@class='col-md-12 align-bottom']/div[7]/ul/li[5]/span/a")
    WebElement websiteLink;
    @FindBy(xpath="//div[@id='container']/div[2]")
    WebElement pagination;
    @FindBy(xpath="//div[@class='col-xs-12 pagination']/ul/li")
    WebElement lastpage;
    @FindBy(xpath="//div[@id='container']//following::*[@class='more-link']/a")
    WebElement actuallink;
    Details detailspage = new Details();
    public Base() throws IOException
    {
        PageFactory.initElements(driver, this);
    }
    public void fetchData() throws InterruptedException, IOException, Exception
    {
        List<WebElement> moreLinks = driver.findElements(By.xpath("//div[@id='container']//following::*[@class='more-link']/a"));
        int count = moreLinks.size();
        System.out.println("no of more links --" +count);
        JavascriptExecutor jse = (JavascriptExecutor) driver;
        for(WebElement ele : moreLinks)
            {
                ele.click();
                Thread.sleep(5000);
                jse.executeScript("arguments[0].scrollIntoView(true);", contactNum);
                Thread.sleep(5000); 
                String ownername = ownerName.getText();
                System.out.println("ownername info -- " +ownername);
                String ofcadd = ofcAddress.getText();
                System.out.println("ofcadd info -- " +ofcadd);
                String emailid = email.getText();
                System.out.println("emailid info -- " +emailid);
                String number = contactNum.getText();
                System.out.println("number info -- " +number);
                String sitelink = websiteLink.getAttribute("href");
                System.out.println("sitelink info -- " +sitelink);
                driver.navigate().back();
                Thread.sleep(3000);             
                jse.executeScript("arguments[0].scrollIntoView(true);", ele);           
            }
        }
}
Sujanian
  • 55
  • 2
  • 9
  • Try this one -https://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium – The scion Jan 24 '18 at 19:15
  • @thescion no man, this link is not helpful. i know how to scroll into an element or view but i want to scroll again and again on the same page without closing the browser till loop execution is not over. – Sujanian Jan 24 '18 at 19:57
  • Your code trials and the relevant `HTML` please? – undetected Selenium Jan 24 '18 at 21:48

0 Answers0