Pages

Showing posts with label gettext. Show all posts
Showing posts with label gettext. Show all posts

Thursday, 8 March 2012

How can I handle alert dialog box?

Below method will handle the alert dialog displayed and also it will return the alert message displayed.

public String getAlert() { 
     Alert alert = driver.switchTo().alert(); 
     String alertMsg = alert.getText();
     alert.accept();
     return alertMsg; } 

Wednesday, 7 March 2012

How can I get the text of the element?

Using getText() method, we can get the text of the element.


That is,


WebElement gButton = driver.findElement(By.name("btnK"));
String gButtonText = gButton.getText();
System.out.println("The Google search button's display text is "+gButtonText);

The getText() method gets the text of an element. This uses either the textContent (Mozilla-like browsers) or the innerText (IE-like browsers) of the element, which is the rendered text shown to the user.