2014-03-13 27 views
0
按鈕

我有一個表格上的以下兩個按鈕,我需要測試:不能點擊使用Java和硒的webdriver

<div class="ef-buttons"> 

<button value="next" name="action" type="submit"> 
    Continue 
</button> 

<button id="modify_button" value="previous" name="action" type="submit"> 
    Go Back 
</button> 

</div> 

我想點擊Continue按鈕,爲此,我寫了下一段代碼:

By chain = new ByChained(By.className("ef-buttons"),(By.xpath("//*[@value='next']"))); 
    driver.findElement(chain).click(); 

但是,每次我收到消息Can not locate an element。我究竟做錯了什麼?

回答

2

我建議整合你的By,並只使用CSS。它更快,更容易。這是你會如何選擇你的元素:

driver.findElement(By.cssSelector("div.ef-buttons button[name='action']")).click(); 

僅供參考,這是更好的做法是使用name屬性在value因爲name是比較獨特的。

+0

問題是,NEXT和PREVIOUS按鈕具有相同的'name'屬性。但是,將其更改爲[value ='next']的竅門! Tnx – user3356141

+0

HA!我甚至沒有明白。這是糟糕的設計,但我很高興你想出了它! :) – sircapsalot