我走了一个链接列表,我一个接一个地点击它们,我去了页面的链接并实现了需要执行的操作,然后返回到列表中点击下一个链接,它的工作完美。在硒页面之间导航 - Java
我现在需要的是到循环结束的地方,硒点击前进按钮进入下一页,再次完成此页面的链接计数并重新开始循环。
我不能让硒点击移动,因为它说click();
命令你不能在webelento中使用。
的方法,点击()是未定义的类型列表< WebElement>
这是HTML结构:
<div id="results-pagination">
<h2 id="pagination-heading">Pagination</h2>
<ul class="pagination">
<li class="prev">
<a class="page-link" href="url" title="back" data-li-page="1">< back</a>
</li>
<li class="link">
<a class="page-link" href="url" title="page 2" data-li-page="2">2</a>
</li>
<li class="next">
<a class="page-link" href="next" title="next" data-li-page="next"></a>
</li>
</ul>
</div>
硒代码:
List<org.openqa.selenium.WebElement> numberpages= driver.findElements(By.className("page-link"));
System.out.println("numberpages : " + numerospaginas.size());
List<org.openqa.selenium.WebElement> links= driver.findElements(By.linkText("to connect"));
System.out.println("Count to connect : " + links.size());
Thread.sleep(2000);
for(int i=0;i<5;i++){
links= driver.findElements(By.linkText("to connect"));
links.get(i).click();
Thread.sleep(2000);
boolean convite = driver.getPageSource().contains("iweReconnectSubmit");
if(invite == true){
Thread.sleep(2000);
boolean error = driver.getPageSource().contains("message:");
do{
//action
By tipoPlano = By.cssSelector("[name='reason'][value='IF'][type='radio']");
driver.findElement(tipoPlano).click();
}while(error == true);
//submit
driver.findElement(By.name("iweReconnectSubmit")).click();
Thread.sleep(2000);
WebDriverWait confirmacaoadicao = new WebDriverWait(driver, 10);
confirmacaoadicao.until(ExpectedConditions.textToBePresentInElement(By.id("control_gen_3"), "invite for: "));
String pessoa = driver.findElement(By.xpath("//div[@id='control_gen_3']//a")).getText();
System.out.println(pessoa + " add");
driver.navigate().to(list_of_links);
WebDriverWait retorno = new WebDriverWait(driver, 10);
retorno.until(ExpectedConditions.elementToBeClickable(By.linkText("To connect")));
}
}
//does not work
driver.findElements(By.linkText("next")).click();
//does not work
((org.openqa.selenium.WebElement)driver.findElements(By.linkText("next"))).click();
我已经试过这种方式不起作用,它不能识别click();命令。方法click()未定义类型列表 –
@PauloSilva注意'driver.findElement'的拼写。没有'''最后。 – Guy