Handling button events in Selenium

                                                     
Button is one of the web element/control on web application,

In a webpage, to identify if a web element is button or not, just look into the DOM and find any tag that is "input", like: [here the event could be clicking a button]


Let's see the implementation



lets see how to handle button events using selenium,

package testPkg;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WebDriverTest {

 public static void main(String[] args) {
  WebDriver driver = new FirefoxDriver();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  driver.get("http://www.qavalidation.com/p/demo.html");
  WebElement btn_click = driver.findElement(By.name("commit"));
  btn_click.click();
  //or, we can even directly identify the element and perform action
  //driver.findElement(By.name("commit")).click();
 }
}

No comments:

Post a Comment