< 1 2 3 4 5 6 7 8 9 10>
我需要点击>
这意味着到表格的下一页
和我使用的代码
WebDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://list.qoo10.sg/item/REAL-JAPAN-VERSION-WORTH-120-24K/412131433");
WebElement findElement1 =
driver.findElement(By.cssSelector("td#opinion_point_1.rating"));
String htmlTableText = findElement1.getText();
System.out.println(htmlTableText);
TimeUnit.SECONDS.sleep(10);
//next click
WebElement click_button =
driver.findElement(By.cssSelector("div#paging.pagingInfo div.center a.next"));
boolean click2=click_button.getAttribute("href").contains("javascript:opinionList(2)");
click_button.click();
TimeUnit.SECONDS.sleep(10);
WebElement findElement2 =
driver.findElement(By.cssSelector("td#opinion_point_1.rating"));
String htmlTableText2 = findElement2.getText();
System.out.println(htmlTableText2);
driver.close();
driver.quit();
我在点击之前打印元素&之后但它没有改变。这意味着不执行单击。有什么建议?
我已经尝试了以下修复但是我得到了相同的结果
click_button.sendKeys(Keys.ENTER);
和
Actions action = new Actions(driver);
action.moveToElement(click_button).click().perform();
和
WebDriverWait wait = new WebDriverWait(driver, 10);
click_button = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("div#paging.pagingInfo div.center a.next")));
click_button.click();
答案 0 :(得分:0)
首先,您需要点击'下一页',使用以下xpath,此xpath完全指向>
图标:
//Wait for the next button
WebDriverWait wait = new WebDriverWait(driver, 10);
click_button = wait.until(ExpectedConditions.visibilityOfElementLocated(By.Xpath("//div[@id='paging']//a[@class='next']/span[text()='next']")));
//Click next button
click_button.click();
然后,点击后尝试等待[2]
(即第二个)页面图标突出显示。这个网站设置了班级'当前'对于所选页面:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.Xpath("//div[@id='paging']//a[@class='current'][text()='2']")));