← Back to list

Click with Confidence: Testing Button Actions Using Selenium WebDriver

This article will walk you through working with a Button , using a simple example built with Selenium WebDriver and TestNG.

Diyana_Hewage · 2025-07-01 18:56 · 0 claps · 1.4 min read
#automation #selenium #testng #button #webdriver
Open on Medium ↗

Click with Confidence: Testing Button Actions Using Selenium WebDriver

This article will walk you through working with a Button , using a simple example built with Selenium WebDriver and TestNG.

What is Button?

A button is a common web element used to perform actions such as submitting , navigating , triggering , and more.

In this quick guide, you’ll learn how to effectively interact with buttons and validate their behavior .

  1. Click on the button and Confirm the title of the page
WebElement loginButton=driver.findElement(By.xpath("//button[@type='submit']"));
loginButton.click();

verify the title of the button using assertions

String expectedTitile="OrangeHRM";
String actualTitle= driver.getTitle();
Assert.assertEquals(actualTitle,expectedTitile,"Title is not matching ")

2.Find the position of the button

WebElement loginButton=driver.findElement(By.xpath("//button[@type='submit']"));
Point xyPoint= loginButton.getLocation();
        int x=xyPoint.getX();
        int y=xyPoint.getY();
 System.out.println("X point is "+ x +" "+ "Y point is"+ y);

3.Find the color of the button

WebElement loginButton=driver.findElement(By.xpath("//button[@type='submit']"));
        String colorofLoginButton= loginButton.getCssValue("background-color");
        System.out.println("Login button's color is "+ colorofLoginButton);

4.Find the size of the button

WebElement loginButton=driver.findElement(By.xpath("//button[@type='submit']"));
        int height=loginButton.getSize().getHeight();
        int width=loginButton.getSize().getWidth();
        System.out.println("Login Button's height is "+ height );
        System.out.println("Login Button's width is "+ width);

5.check that the button is Displayed

WebElement loginButton=driver.findElement(By.xpath("//button[@type='submit']"));
loginButton.isDisplayed();

6.check that the button is Enabled

WebElement loginButton=driver.findElement(By.xpath("//button[@type='submit']"));
loginButton.isEnabled();

In this example, I’m using Selenium alongside TestNG

URL used : https://opensource-demo.orangehrmlive.com/web/index.php/auth/login

Hope this helps you work effectively with Buttons in your automation journey.

I’ll be bringing another powerful guide to your testing toolkit soon. Until then, happy clicking and happy testing!


메타데이터
post_id
3f96e11c0dc0
slug
click-with-confidence-testing-button-actions-using-selenium-webdriver-3f96e11c0dc0
url
https://medium.com/@diy2hewage/click-with-confidence-testing-button-actions-using-selenium-webdriver-3f96e11c0dc0
canonical_url
https://medium.com/@diy2hewage/click-with-confidence-testing-button-actions-using-selenium-webdriver-3f96e11c0dc0
author_url
https://medium.com/@diy2hewage
status
ok
fetched_at
2026-07-15 04:21:51