2014-09-23 70 views
1
  1. 轉到網頁元素上點擊:http://list.qoo10.sg/item/REAL-JAPAN-VERSION-WORTH-120-24K/412131433
  2. 向下滾動,直到你到達客戶審覈表
  3. 下表中有分頁標籤看起來像這樣

< 1 2 3 4 5 6 7 8 9 10 >無法使用HtmlUnitDriver

我需要點擊> 這意味着表格的下一頁

和代碼我用

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

是否僅限htmlunit錯誤? – SkorpEN 2014-09-23 19:59:14

+0

代碼運行沒有錯誤,但點擊沒有響應 – XXLend 2014-09-23 20:54:34

+0

它只是htmlunit結果嗎?你是否和其他司機一起嘗試過? – SkorpEN 2014-09-23 21:05:16

回答

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']"))); 
相關問題