我正在尝试在Google中输入selenium
,并在记事本文件中获取结果的所有标题文字。我希望获得所有页面上的所有可用链接,直到搜索的最后一页。但我只得到第一页的链接。当我调试并运行时,它正在工作大约10页。请帮助我。
JAVA代码:
public class weblink
{
public static void main(String[] args) throws IOException, InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "E:\\disha.shah/myWork/eclipse/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.google.co.in/");
driver.findElement(By.id("lst-ib")).sendKeys("Selenium");
driver.findElement(By.id("_fZl")).click();
PrintStream ps = new PrintStream(new File(("E:\\disha1.txt")));
do
{
List<WebElement> findElements = driver.findElements(By.xpath("//*[@id='rso']//h3/a"));
for (WebElement webElement : findElements)
{
System.out.println("-" + webElement.getText()); // for title
//System.out.println(webElement.getAttribute("href")); // for links
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.setOut(ps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
Thread.sleep(1000);
if(driver.findElement(By.linkText("Next")).isDisplayed()== true)
{
driver.findElement(By.linkText("Next")).click();
}
else
{
System.out.println("All Link is Covered");
}
}
while(driver.findElement(By.linkText("Next")).isDisplayed() );
{
//Thread.sleep(2000);
}
}
}
答案 0 :(得分:1)
我做了一些修正。更新的代码如下.-
<p-dataTable [value]="characters">
<p-headerColumnGroup>
<p-row>
<p-column header="Id" [filter]="true">ID</p-column>
</p-row>
</p-headerColumnGroup>
<p-column field="id" header="Id" ></p-column>
</p-dataTable>