Shaikh Farzan
Shaikh Farzan

Reputation: 83

How do check for the content of a button in WebDriver using java?

Code:

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>

how do i check for the content "Explore Flock" from this code

Upvotes: 1

Views: 91

Answers (2)

RNS
RNS

Reputation: 625

You can get button text using

getText

tag

System.out.println(driver.findElement(By.id("")).getText());

Upvotes: 1

Andersson
Andersson

Reputation: 52685

You need to use getText() method or getAttribute(‌​"textContent") or getAttribute(‌​"innerText") instead of getAttribute(‌​"text") as WebElement has no such attribute as text

Upvotes: 2

Related Questions