2017-04-19 40 views
1

代碼:如何使用java檢查WebDriver中按鈕的內容?

String ButtonHolder = driver.findElement(By.xpath("//div[@id='block-success']//but‌​ton")).getAttribute(‌​"text");' 
System.out.println(ButtonHolder); 

HTML

<button class="join-btn explore-flock">Explore Flock</button> 

如何檢查的內容從該代碼

+0

告訴你如何試圖按鈕上的文字。也讓我們知道你是什麼意思*檢查內容* – Andersson

+0

String ButtonHolder = driver.findElement(By.xpath(「// div [@ id ='block-success'] // button」))。getAttribute 「文本」); \t \t \t System.out.println(ButtonHolder); 我想檢查網站上的按鈕內容是什麼@Andersson –

+0

可能的重複[如何使用硒獲取WebElement文本](http://stackoverflow.com/questions/37298400/how-to-get-webelement-text -with硒) – JeffC

回答

2

您需要使用getText()方法或getAttribute(‌​"textContent")getAttribute(‌​"innerText")代替getAttribute(‌​"text") 「探索羊羣」 as WebElement has no such attribute such as text

1

你可以使用

的getText

標籤

System.out.println(driver.findElement(By.id("")).getText()); 
相關問題