0
我需要經過產品列表:迭代中的幾頁硒Java產品列表
- 點擊它
- 進行產品頁面上的一些行動(這些行動是簡單,已經取得)
- 回到那個我已經上
- 重複該頁面
的所有產品經過整理列表該當前頁面的產品列表,我希望能夠點擊下一頁,並執行與下一頁上的產品相同的過程。
這就是問題:當它到達當前頁面的10個項目時,我不知道如何切換到另一個頁面並重新開始。
示例代碼的html:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Produtos</title>
<meta charset="utf-8">
</head>
<body>
<div class="srp-actions blue-button"><a class="primary-action-button label" href="">Produto 1</a></div>
<div class="srp-actions blue-button"><a class="primary-action-button label" href="">Produto 2</a></div>
<div class="srp-actions blue-button"><a class="primary-action-button label" href="">Produto 3</a></div>
<div class="srp-actions blue-button"><a class="primary-action-button label" href="">Produto 4</a></div>
<br/>
<div id="pagination">
<ul class="pagination">
<li class="active">1</li>
<li class="link"><a class="page-link" href="" title="Página 2">2</a></li>
<li class="link"><a class="page-link" href="" title="Página 2">3</a></li>
<li class="link"><a class="page-link" href="" title="Página 2">4</a></li>
<li class="next"><a class="page-link" href="" rel="next" title="Avançar">next</a></li>
</ul>
</div>
</body>
</html>
JAVA代碼:
int size = driver.findElements(By.className("page-link")).size();
System.out.println("Numero de paginas : " + size);
for(int j = 1 ; j < size ; j++) {
if (j < 2) {// we don't need to navigate to the first page
driver.findElement(By.linkText("Avançar >")).click(); // navigate to page number j
}
String pagesearch = driver.getCurrentUrl();
for(int i=1;i< links.size();i++){
links= driver.findElements(By.linkText("Produto"));
WebDriverWait wait3 = new WebDriverWait(driver, 30);
wait3.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.linkText("Produto")));
links.get(i).click();
Thread.sleep(2000);