我有一个链接列表,并希望每次循环迭代时滚动到一个新链接。当前视图中只能看到一个链接。是否可以滚动浏览网页元素列表?
这是网址链接 - https://www.caknowledgeclub.com/caauditfirms
我希望从每个链接获取数据,我需要滚动到更多链接,但到目前为止还没有。
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);
}
}
}