Log in
updated 11:29 AM UTC, May 4, 2016

How to find a button/input using its name on a webpage using selenium

  • Written by Madhu V Rao
  • Published in Automation

here is a small code snippet to find the button by its name


public WebElement button(String label) {
		By xpathForButton = By
				.xpath("//input[@type='submit' and @value='" + label + "']|//button[@type='submit' and normalize-space()='" +label+"']");

		List<WebElement> eles = this.we.findElements(xpathForButton);
		WebElement returnEle = null;
		for(WebElement ele: eles ) {
			if(ele.isDisplayed()) {
				returnEle = ele;
		if(Config.DEBUG) {
			System.out.println("Webelement found: "+ (we !=null? returnEle.getTagName() : we) );
		return returnEle;

this.we = this.driver.findElement(By.tagName("body"))

Powered by Bullraider.com
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest