Popular Searches
Popular Course Categories
Popular Courses

Buttons

HTML & Web Elements

<div class="selenium-notes">

<h1>Buttons in Selenium</h1>

<p>Buttons are one of the most important interactive web elements used in modern web applications. A button allows users to perform an action such as submitting a form, logging in, registering an account, searching for information, adding a product to a cart, saving data, opening a dialog, navigating to another section, or confirming an operation.</p>

<p>In Selenium WebDriver, buttons are treated as WebElement objects. Selenium provides methods such as <code>click()</code>, <code>isDisplayed()</code>, <code>isEnabled()</code>, <code>getText()</code>, <code>getAttribute()</code>, and explicit waits to interact with and validate buttons.</p>

<p>Buttons are a core part of Selenium WebDriver automation because real-world applications contain many user actions that are triggered by buttons.</p>

<hr>

<h2>1. What is a Button?</h2>

<p>A button is a graphical user interface element that allows a user to perform an action when it is clicked or activated.</p>

<p>A basic HTML button can be created using:</p>

<pre><code>&lt;button id="login"&gt;Login&lt;/button&gt;</code></pre>

<p>In Selenium, the button can be located using its ID:</p>

<pre><code>WebElement loginButton = driver.findElement(By.id("login"));

loginButton.click();</code></pre>

<hr>

<h2>2. Why Buttons are Important in Selenium?</h2>

<p>Buttons are responsible for triggering many important application workflows. Selenium automation frequently interacts with buttons to execute and validate these workflows.</p>

<ul>

<li>Login</li>

<li>Logout</li>

<li>Registration</li>

<li>Search</li>

<li>Submit</li>

<li>Save</li>

<li>Update</li>

<li>Delete</li>

<li>Add to Cart</li>

<li>Checkout</li>

<li>Continue</li>

<li>Next</li>

<li>Previous</li>

<li>Cancel</li>

<li>Confirm</li>

<li>Download</li>

</ul>

<hr>

<h2>3. HTML Button Element</h2>

<p>The standard HTML button element is represented using the <code>&lt;button&gt;</code> tag.</p>

<pre><code>&lt;button type="button" id="saveButton"&gt;Save&lt;/button&gt;</code></pre>

<p>The <code>type</code> attribute commonly contains values such as:</p>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Type</th><th>Purpose</th></tr>

<tr><td>button</td><td>Generic button used for custom actions.</td></tr>

<tr><td>submit</td><td>Submits a form.</td></tr>

<tr><td>reset</td><td>Resets form controls to their initial values.</td></tr>

</table>

<hr>

<h2>4. Button as a WebElement</h2>

<p>Selenium represents a button as a <code>WebElement</code>.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

button.click();</code></pre>

<p>Once Selenium identifies the button, different WebElement methods can be used to inspect or interact with it.</p>

<hr>

<h2>5. Locating Buttons by ID</h2>

<p>If a button has a unique and stable ID, <code>By.id()</code> is a simple way to locate it.</p>

<pre><code>WebElement loginButton = driver.findElement(By.id("loginButton"));

loginButton.click();</code></pre>

<p>HTML:</p>

<pre><code>&lt;button id="loginButton"&gt;Login&lt;/button&gt;</code></pre>

<hr>

<h2>6. Locating Buttons by Name</h2>

<p>A button can be located using the <code>name</code> attribute.</p>

<pre><code>WebElement submitButton = driver.findElement(By.name("submit"));

submitButton.click();</code></pre>

<p>HTML:</p>

<pre><code>&lt;button name="submit"&gt;Submit&lt;/button&gt;</code></pre>

<hr>

<h2>7. Locating Buttons by Class Name</h2>

<p>If a button contains a unique class, it can be located using <code>By.className()</code>.</p>

<pre><code>WebElement button = driver.findElement(By.className("login-button"));

button.click();</code></pre>

<p>When multiple CSS classes are present, use a suitable CSS selector instead of passing multiple classes to <code>By.className()</code>.</p>

<hr>

<h2>8. Locating Buttons by Tag Name</h2>

<p>The HTML tag name <code>button</code> can be used as a locator.</p>

<pre><code>List&lt;WebElement&gt; buttons = driver.findElements(By.tagName("button"));

 

System.out.println("Total buttons: " + buttons.size());</code></pre>

<p>Tag name is useful when working with collections of buttons, but it may not uniquely identify a specific button.</p>

<hr>

<h2>9. Locating Buttons by Link Text</h2>

<p>Some elements visually look like buttons but are actually HTML links represented by the <code>&lt;a&gt;</code> element.</p>

<pre><code>&lt;a href="/login"&gt;Login&lt;/a&gt;</code></pre>

<p>Such an element can be located using link text:</p>

<pre><code>WebElement login = driver.findElement(By.linkText("Login"));

login.click();</code></pre>

<hr>

<h2>10. Locating Buttons by Partial Link Text</h2>

<p>If the complete link text is dynamic or lengthy, partial link text can sometimes be used.</p>

<pre><code>WebElement login = driver.findElement(By.partialLinkText("Log"));

login.click();</code></pre>

<p>Use partial link text carefully because multiple elements may contain the same text.</p>

<hr>

<h2>11. Locating Buttons Using CSS Selector</h2>

<p>CSS selectors are useful for creating concise and flexible button locators.</p>

<pre><code>WebElement button = driver.findElement(By.cssSelector("#loginButton"));

button.click();</code></pre>

<p>By class:</p>

<pre><code>WebElement button = driver.findElement(By.cssSelector(".login-button"));

button.click();</code></pre>

<p>By attribute:</p>

<pre><code>WebElement button = driver.findElement(By.cssSelector("button[type='submit']"));

button.click();</code></pre>

<hr>

<h2>12. Locating Buttons Using XPath</h2>

<p>XPath is commonly used when a button requires a more specific locator.</p>

<pre><code>WebElement button = driver.findElement(By.xpath("//button[@id='loginButton']"));

button.click();</code></pre>

<p>XPath using button text:</p>

<pre><code>WebElement button = driver.findElement(By.xpath("//button[text()='Login']"));

button.click();</code></pre>

<hr>

<h2>13. XPath Using contains()</h2>

<p>The <code>contains()</code> function is useful when the button text or attribute contains dynamic content.</p>

<pre><code>WebElement button = driver.findElement(

    By.xpath("//button[contains(text(),'Login')]")

);

button.click();</code></pre>

<hr>

<h2>14. XPath Using starts-with()</h2>

<p>The <code>starts-with()</code> function can be used when an attribute begins with a stable value.</p>

<pre><code>WebElement button = driver.findElement(

    By.xpath("//button[starts-with(@id,'login_')]")

);

button.click();</code></pre>

<hr>

<h2>15. click() Method</h2>

<p>The <code>click()</code> method is the most commonly used Selenium method for interacting with buttons.</p>

<pre><code>WebElement loginButton = driver.findElement(By.id("login"));

loginButton.click();</code></pre>

<p>When the button is interactable, Selenium performs a browser-level click on the element.</p>

<hr>

<h2>16. Basic Button Automation Flow</h2>

<pre><code>Open Browser

      ↓

Open Application

      ↓

Navigate to Required Page

      ↓

Locate Button

      ↓

Verify Button

      ↓

Wait if Required

      ↓

Click Button

      ↓

Application Performs Action

      ↓

Verify Expected Result</code></pre>

<hr>

<h2>17. Checking Button Visibility</h2>

<p>The <code>isDisplayed()</code> method checks whether a button is displayed.</p>

<pre><code>WebElement button = driver.findElement(By.id("login"));

 

if(button.isDisplayed()){

    System.out.println("Login button is displayed");

}</code></pre>

<hr>

<h2>18. Checking Button Enabled State</h2>

<p>The <code>isEnabled()</code> method checks whether a button is enabled.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

 

if(button.isEnabled()){

    System.out.println("Submit button is enabled");

}</code></pre>

<p>This is especially useful for applications where buttons become enabled only after required fields are completed.</p>

<hr>

<h2>19. Checking Disabled Buttons</h2>

<p>A disabled button cannot normally be activated by a user.</p>

<p>Example HTML:</p>

<pre><code>&lt;button id="submit" disabled&gt;Submit&lt;/button&gt;</code></pre>

<p>Selenium can verify its state:</p>

<pre><code>WebElement submit = driver.findElement(By.id("submit"));

 

if(!submit.isEnabled()){

    System.out.println("Submit button is disabled");

}</code></pre>

<hr>

<h2>20. Button Text Validation</h2>

<p>The <code>getText()</code> method can retrieve the visible text of a button.</p>

<pre><code>WebElement button = driver.findElement(By.id("login"));

 

String buttonText = button.getText();

 

System.out.println(buttonText);</code></pre>

<p>TestNG assertion:</p>

<pre><code>Assert.assertEquals(button.getText(), "Login");</code></pre>

<hr>

<h2>21. Button Attribute Validation</h2>

<p>The <code>getAttribute()</code> method can be used to retrieve attributes of a button.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

 

String type = button.getAttribute("type");

String id = button.getAttribute("id");

String name = button.getAttribute("name");

String className = button.getAttribute("class");

 

System.out.println(type);

System.out.println(id);

System.out.println(name);

System.out.println(className);</code></pre>

<hr>

<h2>22. Button Type Validation</h2>

<p>A test can verify the type of a button.</p>

<pre><code>WebElement submitButton = driver.findElement(By.id("submit"));

 

String type = submitButton.getAttribute("type");

 

Assert.assertEquals(type, "submit");</code></pre>

<hr>

<h2>23. Submit Button</h2>

<p>A submit button is commonly used to submit form data.</p>

<pre><code>&lt;button type="submit" id="submit"&gt;Submit&lt;/button&gt;</code></pre>

<p>Selenium example:</p>

<pre><code>WebElement submit = driver.findElement(By.id("submit"));

submit.click();</code></pre>

<hr>

<h2>24. Login Button</h2>

<p>Login buttons are commonly used to submit username and password information.</p>

<pre><code>WebElement username = driver.findElement(By.id("username"));

WebElement password = driver.findElement(By.id("password"));

WebElement login = driver.findElement(By.id("login"));

 

username.sendKeys("testuser");

password.sendKeys("Test@123");

login.click();</code></pre>

<hr>

<h2>25. Register Button</h2>

<p>Registration pages usually contain a button that submits user information.</p>

<pre><code>WebElement register = driver.findElement(By.id("register"));

register.click();</code></pre>

<hr>

<h2>26. Search Button</h2>

<p>A search button triggers a search operation.</p>

<pre><code>WebElement searchBox = driver.findElement(By.id("search"));

WebElement searchButton = driver.findElement(By.id("searchButton"));

 

searchBox.sendKeys("Selenium");

searchButton.click();</code></pre>

<hr>

<h2>27. Save Button</h2>

<p>Save buttons are commonly used in profile, settings, administration, and data-entry applications.</p>

<pre><code>WebElement saveButton = driver.findElement(By.id("save"));

saveButton.click();</code></pre>

<hr>

<h2>28. Update Button</h2>

<p>An update button can be used to save changes to existing records.</p>

<pre><code>WebElement updateButton = driver.findElement(By.id("update"));

updateButton.click();</code></pre>

<hr>

<h2>29. Delete Button</h2>

<p>Delete buttons require special attention because they may perform destructive operations.</p>

<pre><code>WebElement deleteButton = driver.findElement(By.id("delete"));

deleteButton.click();</code></pre>

<p>If the application displays a confirmation dialog, the test should handle that dialog and verify the intended result.</p>

<hr>

<h2>30. Cancel Button</h2>

<p>A cancel button generally closes a form, dialog, or pending operation.</p>

<pre><code>WebElement cancelButton = driver.findElement(By.id("cancel"));

cancelButton.click();</code></pre>

<hr>

<h2>31. Reset Button</h2>

<p>A reset button can clear form controls or restore them to their initial state depending on the application's implementation.</p>

<pre><code>&lt;button type="reset" id="reset"&gt;Reset&lt;/button&gt;</code></pre>

<p>Selenium:</p>

<pre><code>driver.findElement(By.id("reset")).click();</code></pre>

<hr>

<h2>32. Next Button</h2>

<p>Next buttons are frequently used in multi-step forms, checkout workflows, and wizards.</p>

<pre><code>WebElement nextButton = driver.findElement(By.id("next"));

nextButton.click();</code></pre>

<hr>

<h2>33. Previous Button</h2>

<p>Previous buttons allow users to move back to an earlier step.</p>

<pre><code>WebElement previousButton = driver.findElement(By.id("previous"));

previousButton.click();</code></pre>

<hr>

<h2>34. Continue Button</h2>

<p>Continue buttons are commonly found in checkout and multi-step workflows.</p>

<pre><code>WebElement continueButton = driver.findElement(By.id("continue"));

continueButton.click();</code></pre>

<hr>

<h2>35. Add to Cart Button</h2>

<p>E-commerce applications commonly use Add to Cart buttons.</p>

<pre><code>WebElement addToCart = driver.findElement(By.id("addToCart"));

addToCart.click();</code></pre>

<p>After clicking, the test should verify that the product was added successfully.</p>

<hr>

<h2>36. Checkout Button</h2>

<p>A checkout button usually moves the user from the cart to the checkout workflow.</p>

<pre><code>WebElement checkout = driver.findElement(By.id("checkout"));

checkout.click();</code></pre>

<hr>

<h2>37. Download Button</h2>

<p>A download button may trigger a file download.</p>

<pre><code>WebElement download = driver.findElement(By.id("download"));

download.click();</code></pre>

<p>After clicking, a test can verify the expected application response or, where appropriate, verify the downloaded file using a suitable file-handling strategy.</p>

<hr>

<h2>38. Button with Image</h2>

<p>Some buttons contain an image instead of visible text.</p>

<pre><code>&lt;button id="searchButton"&gt;

    &lt;img src="search.png" alt="Search"&gt;

&lt;/button&gt;</code></pre>

<p>The button can still be located using its ID:</p>

<pre><code>driver.findElement(By.id("searchButton")).click();</code></pre>

<hr>

<h2>39. Button with Icon</h2>

<p>Modern web applications often use icon buttons.</p>

<pre><code>&lt;button id="menuButton" aria-label="Open Menu"&gt;

    &lt;span class="menu-icon"&gt;&lt;/span&gt;

&lt;/button&gt;</code></pre>

<p>A stable attribute such as <code>id</code> or <code>aria-label</code> can be useful for locating the button.</p>

<pre><code>WebElement menu = driver.findElement(

    By.cssSelector("button[aria-label='Open Menu']")

);

menu.click();</code></pre>

<hr>

<h2>40. Button with Dynamic Text</h2>

<p>Sometimes button text changes according to application state.</p>

<pre><code>&lt;button id="action"&gt;Save Changes&lt;/button&gt;</code></pre>

<p>A locator based on a stable ID can be more reliable than depending on changing visible text.</p>

<pre><code>driver.findElement(By.id("action")).click();</code></pre>

<hr>

<h2>41. Dynamic Buttons</h2>

<p>Dynamic buttons may appear only after a particular action or may be enabled after an asynchronous operation.</p>

<pre><code>WebElement continueButton = driver.findElement(By.id("continue"));

continueButton.click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement nextButton = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("next"))

);

 

nextButton.click();</code></pre>

<hr>

<h2>42. Explicit Wait for Button</h2>

<p>Explicit waits are useful when a button takes time to become available.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement loginButton = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("login"))

);

 

loginButton.click();</code></pre>

<hr>

<h2>43. Visibility Wait for Button</h2>

<p>If the main requirement is that the button becomes visible, use a visibility condition.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement button = wait.until(

    ExpectedConditions.visibilityOfElementLocated(By.id("submit"))

);</code></pre>

<hr>

<h2>44. Presence Wait for Button</h2>

<p>Presence checks whether the element exists in the DOM.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement button = wait.until(

    ExpectedConditions.presenceOfElementLocated(By.id("submit"))

);</code></pre>

<p>Presence does not necessarily mean that the button is visible or clickable.</p>

<hr>

<h2>45. Clickable Button</h2>

<p>When the button needs to be clicked, <code>elementToBeClickable()</code> is often appropriate.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

 

button.click();</code></pre>

<hr>

<h2>46. Disabled Button Becomes Enabled</h2>

<p>Many applications disable the Submit button until required fields are completed.</p>

<pre><code>WebElement username = driver.findElement(By.id("username"));

WebElement password = driver.findElement(By.id("password"));

 

username.sendKeys("testuser");

password.sendKeys("Test@123");

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement submit = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

 

submit.click();</code></pre>

<hr>

<h2>47. Button Covered by an Overlay</h2>

<p>A button may be visible but another element such as a loading overlay, modal, popup, or cookie banner may block it.</p>

<p>In such cases, identify the blocking element and wait until it disappears before clicking the button.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

wait.until(ExpectedConditions.invisibilityOfElementLocated(

    By.cssSelector(".loading-overlay")

));

 

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

 

button.click();</code></pre>

<hr>

<h2>48. ElementClickInterceptedException</h2>

<p><code>ElementClickInterceptedException</code> can occur when another element receives the click instead of the intended button.</p>

<p>Common causes include:</p>

<ul>

<li>Popup overlay</li>

<li>Loading screen</li>

<li>Cookie banner</li>

<li>Modal dialog</li>

<li>Sticky header</li>

<li>Animation</li>

<li>Incorrect element position</li>

</ul>

<p>The preferred approach is to understand and resolve the actual page synchronization or UI issue rather than immediately using JavaScript.</p>

<hr>

<h2>49. ElementNotInteractableException</h2>

<p>This exception can occur when Selenium finds an element but cannot interact with it in its current state.</p>

<p>Possible causes include:</p>

<ul>

<li>Element is hidden.</li>

<li>Element is disabled.</li>

<li>Element is outside the expected interaction state.</li>

<li>Page has not completed loading.</li>

<li>Incorrect element was located.</li>

</ul>

<hr>

<h2>50. Stale Button Element</h2>

<p>A button reference can become stale when the DOM is refreshed or the button is replaced dynamically.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

 

driver.navigate().refresh();

 

button.click();</code></pre>

<p>The original WebElement may no longer represent the current DOM element. Re-locate the button after the DOM update.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

button.click();</code></pre>

<hr>

<h2>51. Buttons Inside Iframes</h2>

<p>If a button exists inside an iframe, Selenium must switch into that iframe before interacting with the button.</p>

<pre><code>WebElement frame = driver.findElement(By.id("paymentFrame"));

driver.switchTo().frame(frame);

 

WebElement payButton = driver.findElement(By.id("pay"));

payButton.click();

 

driver.switchTo().defaultContent();</code></pre>

<hr>

<h2>52. Buttons Inside Shadow DOM</h2>

<p>Modern component-based applications may place buttons inside Shadow DOM.</p>

<pre><code>WebElement host = driver.findElement(By.cssSelector("custom-component"));

 

SearchContext shadowRoot = host.getShadowRoot();

 

WebElement button = shadowRoot.findElement(

    By.cssSelector("button")

);

 

button.click();</code></pre>

<hr>

<h2>53. Multiple Buttons on a Page</h2>

<p>When multiple buttons exist, <code>findElements()</code> can retrieve them as a collection.</p>

<pre><code>List&lt;WebElement&gt; buttons = driver.findElements(By.tagName("button"));

 

System.out.println("Total buttons: " + buttons.size());</code></pre>

<hr>

<h2>54. Iterating Through Buttons</h2>

<p>Each button can be inspected individually.</p>

<pre><code>List&lt;WebElement&gt; buttons = driver.findElements(By.tagName("button"));

 

for(WebElement button : buttons){

    System.out.println(button.getText());

}</code></pre>

<hr>

<h2>55. Finding Enabled Buttons</h2>

<pre><code>List&lt;WebElement&gt; buttons = driver.findElements(By.tagName("button"));

 

for(WebElement button : buttons){

    if(button.isEnabled()){

        System.out.println("Enabled Button: " + button.getText());

    }

}</code></pre>

<hr>

<h2>56. Finding Disabled Buttons</h2>

<pre><code>List&lt;WebElement&gt; buttons = driver.findElements(By.tagName("button"));

 

for(WebElement button : buttons){

    if(!button.isEnabled()){

        System.out.println("Disabled Button: " + button.getText());

    }

}</code></pre>

<hr>

<h2>57. Clicking a Button Using Text</h2>

<p>When the visible text is stable, XPath can be used.</p>

<pre><code>WebElement button = driver.findElement(

    By.xpath("//button[normalize-space()='Login']")

);

 

button.click();</code></pre>

<p><code>normalize-space()</code> can help when unwanted whitespace exists around the text.</p>

<hr>

<h2>58. Clicking a Button Using aria-label</h2>

<p>Accessibility attributes can sometimes provide stable and meaningful selectors.</p>

<pre><code>WebElement menuButton = driver.findElement(

    By.cssSelector("button[aria-label='Open Menu']")

);

 

menuButton.click();</code></pre>

<hr>

<h2>59. Clicking a Button Using Data Attributes</h2>

<p>Applications may expose custom data attributes for testing or application behavior.</p>

<pre><code>&lt;button data-testid="login-button"&gt;Login&lt;/button&gt;</code></pre>

<p>Selenium:</p>

<pre><code>WebElement login = driver.findElement(

    By.cssSelector("[data-testid='login-button']")

);

 

login.click();</code></pre>

<p>Stable test-specific attributes can be useful when the application team intentionally provides them for automation.</p>

<hr>

<h2>60. Button Validation Using Assertions</h2>

<p>TestNG assertions can verify button properties.</p>

<pre><code>WebElement login = driver.findElement(By.id("login"));

 

Assert.assertTrue(login.isDisplayed());

Assert.assertTrue(login.isEnabled());

Assert.assertEquals(login.getText(), "Login");</code></pre>

<hr>

<h2>61. Complete Login Button Test</h2>

<pre><code>@Test

public void loginButtonTest(){

 

    WebElement username = driver.findElement(By.id("username"));

    WebElement password = driver.findElement(By.id("password"));

    WebElement login = driver.findElement(By.id("login"));

 

    username.sendKeys("testuser");

    password.sendKeys("Test@123");

 

    Assert.assertTrue(login.isDisplayed());

    Assert.assertTrue(login.isEnabled());

    Assert.assertEquals(login.getText(), "Login");

 

    login.click();

}</code></pre>

<hr>

<h2>62. Button State Testing</h2>

<p>Buttons can have different states depending on application conditions.</p>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>State</th><th>Description</th></tr>

<tr><td>Visible</td><td>Button is displayed on the page.</td></tr>

<tr><td>Hidden</td><td>Button exists but is not visible.</td></tr>

<tr><td>Enabled</td><td>Button can normally be interacted with.</td></tr>

<tr><td>Disabled</td><td>Button is not available for normal user interaction.</td></tr>

<tr><td>Loading</td><td>Button may temporarily show a loading state.</td></tr>

<tr><td>Active</td><td>Button is currently being interacted with.</td></tr>

</table>

<hr>

<h2>63. Button State Validation Example</h2>

<pre><code>WebElement submit = driver.findElement(By.id("submit"));

 

System.out.println("Displayed: " + submit.isDisplayed());

System.out.println("Enabled: " + submit.isEnabled());

System.out.println("Text: " + submit.getText());

System.out.println("Class: " + submit.getAttribute("class"));</code></pre>

<hr>

<h2>64. Submit Button Validation</h2>

<p>A test should verify both the state of the button and the result of clicking it.</p>

<pre><code>WebElement submit = driver.findElement(By.id("submit"));

 

Assert.assertTrue(submit.isDisplayed());

Assert.assertTrue(submit.isEnabled());

 

submit.click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(ExpectedConditions.urlContains("success"));</code></pre>

<hr>

<h2>65. Button Click and Page Navigation</h2>

<p>A button may navigate to another page after clicking.</p>

<pre><code>String oldUrl = driver.getCurrentUrl();

 

driver.findElement(By.id("continue")).click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

wait.until(ExpectedConditions.not(

    ExpectedConditions.urlToBe(oldUrl)

));</code></pre>

<hr>

<h2>66. Button Click and Message Validation</h2>

<p>After clicking a button, the application may display a success message.</p>

<pre><code>driver.findElement(By.id("save")).click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement message = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("successMessage")

    )

);

 

Assert.assertEquals(message.getText(), "Saved successfully");</code></pre>

<hr>

<h2>67. Button Click and Modal Validation</h2>

<p>Buttons may open modal dialogs.</p>

<pre><code>driver.findElement(By.id("openModal")).click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement modal = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("modal")

    )

);

 

Assert.assertTrue(modal.isDisplayed());</code></pre>

<hr>

<h2>68. Button Click and Alert Handling</h2>

<p>Some buttons display JavaScript alerts.</p>

<pre><code>driver.findElement(By.id("delete")).click();

 

Alert alert = driver.switchTo().alert();

 

System.out.println(alert.getText());

 

alert.accept();</code></pre>

<p>For a cancel operation:</p>

<pre><code>Alert alert = driver.switchTo().alert();

alert.dismiss();</code></pre>

<hr>

<h2>69. Confirmation Button</h2>

<p>A confirmation workflow may contain buttons such as Confirm and Cancel.</p>

<pre><code>driver.findElement(By.id("delete")).click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement confirm = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("confirmDelete"))

);

 

confirm.click();</code></pre>

<hr>

<h2>70. Mouse Hover and Button</h2>

<p>Some buttons appear only after hovering over a menu or another element.</p>

<pre><code>Actions actions = new Actions(driver);

 

WebElement menu = driver.findElement(By.id("menu"));

actions.moveToElement(menu).perform();

 

WebElement submenuButton = driver.findElement(By.id("submenu"));

submenuButton.click();</code></pre>

<hr>

<h2>71. Scrolling to a Button</h2>

<p>If a button is outside the current viewport, Selenium may need to scroll it into a suitable position before interacting with it.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

 

((JavascriptExecutor) driver).executeScript(

    "arguments[0].scrollIntoView({block:'center'});",

    button

);

 

button.click();</code></pre>

<p>Scrolling should be used when necessary. It is often better to rely on normal WebDriver interaction after ensuring the element is available.</p>

<hr>

<h2>72. JavaScript Click</h2>

<p>JavaScript can technically trigger a click on an element.</p>

<pre><code>WebElement button = driver.findElement(By.id("submit"));

 

JavascriptExecutor js = (JavascriptExecutor) driver;

 

js.executeScript("arguments[0].click();", button);</code></pre>

<p>This should generally be considered a fallback for special cases rather than the default approach. A JavaScript-triggered click may not reproduce every detail of a real user interaction.</p>

<hr>

<h2>73. Why Normal click() is Preferred</h2>

<p>Selenium's normal <code>click()</code> method is generally preferred because it follows WebDriver's interaction model and allows the browser to perform the interaction under normal element-interaction rules.</p>

<ul>

<li>It better represents normal browser interaction.</li>

<li>It can reveal genuine UI synchronization problems.</li>

<li>It helps detect overlays and obstructed elements.</li>

<li>It keeps tests closer to real user behavior.</li>

</ul>

<hr>

<h2>74. Button Inside a Form</h2>

<p>Buttons are often associated with forms.</p>

<pre><code>&lt;form id="loginForm"&gt;

    &lt;input id="username" type="text"&gt;

    &lt;input id="password" type="password"&gt;

    &lt;button type="submit" id="login"&gt;Login&lt;/button&gt;

&lt;/form&gt;</code></pre>

<p>Selenium can automate the entire form:</p>

<pre><code>driver.findElement(By.id("username")).sendKeys("admin");

driver.findElement(By.id("password")).sendKeys("Admin@123");

driver.findElement(By.id("login")).click();</code></pre>

<hr>

<h2>75. Button and Page Object Model</h2>

<p>In the Page Object Model, button locators are generally maintained inside the corresponding page class.</p>

<pre><code>public class LoginPage {

 

    private WebDriver driver;

 

    private By username = By.id("username");

    private By password = By.id("password");

    private By loginButton = By.id("login");

 

    public LoginPage(WebDriver driver){

        this.driver = driver;

    }

 

    public void login(String user, String pass){

        driver.findElement(username).sendKeys(user);

        driver.findElement(password).sendKeys(pass);

        driver.findElement(loginButton).click();

    }

}</code></pre>

<hr>

<h2>76. Reusable Button Click Method</h2>

<p>A utility method can centralize common button interactions.</p>

<pre><code>public void clickButton(By locator){

 

    WebElement button = driver.findElement(locator);

 

    if(button.isDisplayed() &amp;&amp; button.isEnabled()){

        button.click();

    }

}</code></pre>

<p>Usage:</p>

<pre><code>clickButton(By.id("login"));

clickButton(By.id("submit"));

clickButton(By.id("save"));</code></pre>

<hr>

<h2>77. Reusable Wait and Click Method</h2>

<pre><code>public void waitAndClick(By locator){

 

    WebDriverWait wait = new WebDriverWait(

        driver,

        Duration.ofSeconds(10)

    );

 

    WebElement button = wait.until(

        ExpectedConditions.elementToBeClickable(locator)

    );

 

    button.click();

}</code></pre>

<hr>

<h2>78. Generic Button Validation Method</h2>

<pre><code>public boolean isButtonReady(By locator){

 

    WebElement button = driver.findElement(locator);

 

    return button.isDisplayed() &amp;&amp; button.isEnabled();

}</code></pre>

<p>Usage:</p>

<pre><code>if(isButtonReady(By.id("submit"))){

    System.out.println("Submit button is ready");

}</code></pre>

<hr>

<h2>79. Testing Multiple Buttons</h2>

<p>Multiple buttons can be inspected and validated in a single test.</p>

<pre><code>List&lt;WebElement&gt; buttons = driver.findElements(

    By.cssSelector("button")

);

 

for(WebElement button : buttons){

 

    String text = button.getText();

 

    System.out.println(

        "Button: " + text +

        " | Enabled: " + button.isEnabled() +

        " | Displayed: " + button.isDisplayed()

    );

}</code></pre>

<hr>

<h2>80. Dynamic Button Example</h2>

<p>Consider an application where the Submit button remains disabled until mandatory fields are completed.</p>

<pre><code>WebElement submit = driver.findElement(By.id("submit"));

 

Assert.assertFalse(submit.isEnabled());

 

driver.findElement(By.id("username")).sendKeys("admin");

driver.findElement(By.id("email")).sendKeys("[email protected]");

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

submit = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

 

submit.click();</code></pre>

<hr>

<h2>81. E-Commerce Button Automation</h2>

<p>E-commerce applications contain many buttons that can be automated using Selenium.</p>

<ul>

<li>Search</li>

<li>Add to Cart</li>

<li>Buy Now</li>

<li>Remove</li>

<li>Apply Coupon</li>

<li>Update Cart</li>

<li>Checkout</li>

<li>Continue Shopping</li>

<li>Place Order</li>

</ul>

<p>Example:</p>

<pre><code>driver.findElement(By.id("addToCart")).click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement checkout = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("checkout"))

);

 

checkout.click();</code></pre>

<hr>

<h2>82. Registration Button Automation</h2>

<pre><code>driver.findElement(By.id("firstName")).sendKeys("Rahul");

driver.findElement(By.id("lastName")).sendKeys("Sharma");

driver.findElement(By.id("email")).sendKeys("[email protected]");

driver.findElement(By.id("password")).sendKeys("Rahul@123");

 

WebElement register = driver.findElement(By.id("register"));

 

Assert.assertTrue(register.isDisplayed());

Assert.assertTrue(register.isEnabled());

 

register.click();</code></pre>

<hr>

<h2>83. Search Button Automation</h2>

<pre><code>WebElement searchBox = driver.findElement(By.id("search"));

WebElement searchButton = driver.findElement(By.id("searchButton"));

 

searchBox.clear();

searchBox.sendKeys("Selenium WebDriver");

 

searchButton.click();</code></pre>

<hr>

<h2>84. Save Button Automation</h2>

<pre><code>WebElement save = driver.findElement(By.id("save"));

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

wait.until(ExpectedConditions.elementToBeClickable(save));

 

save.click();

 

WebElement success = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("successMessage")

    )

);

 

Assert.assertTrue(success.isDisplayed());</code></pre>

<hr>

<h2>85. Delete Button Automation</h2>

<p>Delete operations should be automated carefully because they may permanently modify application data.</p>

<pre><code>WebElement delete = driver.findElement(By.id("delete"));

delete.click();

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement confirm = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("confirm"))

);

 

confirm.click();</code></pre>

<hr>

<h2>86. Button Test Scenarios</h2>

<ul>

<li>Verify button is present.</li>

<li>Verify button is displayed.</li>

<li>Verify button is enabled.</li>

<li>Verify button is disabled when expected.</li>

<li>Verify button text.</li>

<li>Verify button type.</li>

<li>Verify button attributes.</li>

<li>Click button.</li>

<li>Verify expected action.</li>

<li>Verify navigation.</li>

<li>Verify success message.</li>

<li>Verify error message.</li>

<li>Verify popup or modal.</li>

<li>Verify confirmation dialog.</li>

<li>Verify button behavior with invalid data.</li>

</ul>

<hr>

<h2>87. Button Test Cases</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Test Case</th><th>Expected Result</th></tr>

<tr><td>Verify Login button visibility</td><td>Login button should be displayed.</td></tr>

<tr><td>Verify Login button enabled state</td><td>Button should be enabled when appropriate.</td></tr>

<tr><td>Click Login</td><td>Login workflow should execute.</td></tr>

<tr><td>Click Submit</td><td>Form should be submitted.</td></tr>

<tr><td>Click Cancel</td><td>Operation should be cancelled.</td></tr>

<tr><td>Click Delete</td><td>Expected confirmation workflow should appear.</td></tr>

<tr><td>Click Save</td><td>Data should be saved successfully.</td></tr>

<tr><td>Click Search</td><td>Expected search results should be displayed.</td></tr>

</table>

<hr>

<h2>88. Common Button Exceptions</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Exception</th><th>Common Cause</th><th>Possible Solution</th></tr>

<tr><td>NoSuchElementException</td><td>Button cannot be located.</td><td>Check locator and page state.</td></tr>

<tr><td>ElementNotInteractableException</td><td>Button cannot currently be interacted with.</td><td>Check visibility and enabled state.</td></tr>

<tr><td>ElementClickInterceptedException</td><td>Another element blocks the button.</td><td>Handle overlays and synchronization.</td></tr>

<tr><td>StaleElementReferenceException</td><td>Button was replaced in the DOM.</td><td>Locate the button again.</td></tr>

<tr><td>TimeoutException</td><td>Expected condition did not occur.</td><td>Check locator, timing, and application state.</td></tr>

</table>

<hr>

<h2>89. Common Mistakes While Handling Buttons</h2>

<ul>

<li>Using unstable locators.</li>

<li>Clicking before the page is ready.</li>

<li>Ignoring disabled button states.</li>

<li>Ignoring loading overlays.</li>

<li>Using Thread.sleep() unnecessarily.</li>

<li>Using JavaScript click as the first solution.</li>

<li>Ignoring iframe boundaries.</li>

<li>Ignoring Shadow DOM.</li>

<li>Not validating the result after clicking.</li>

<li>Using partial text when multiple buttons have similar text.</li>

<li>Using a generic tag locator when a unique locator is available.</li>

<li>Not handling confirmation dialogs.</li>

</ul>

<hr>

<h2>90. Best Practices for Button Automation</h2>

<ul>

<li>Use stable and unique locators.</li>

<li>Prefer unique IDs when they are stable.</li>

<li>Use CSS selectors or XPath when necessary.</li>

<li>Use explicit waits for dynamic buttons.</li>

<li>Verify the button state before interaction when required.</li>

<li>Validate the expected result after clicking.</li>

<li>Handle overlays and popups correctly.</li>

<li>Use Page Object Model in larger automation frameworks.</li>

<li>Create reusable click methods.</li>

<li>Avoid unnecessary JavaScript clicks.</li>

<li>Do not use excessive hard-coded delays.</li>

<li>Keep destructive operations isolated in test environments.</li>

</ul>

<hr>

<h2>91. Locator Comparison for Buttons</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Locator</th><th>Example</th><th>Typical Usage</th></tr>

<tr><td>ID</td><td>By.id("login")</td><td>Unique stable button ID</td></tr>

<tr><td>Name</td><td>By.name("submit")</td><td>Stable name attribute</td></tr>

<tr><td>Class Name</td><td>By.className("login-button")</td><td>Unique class</td></tr>

<tr><td>CSS Selector</td><td>By.cssSelector("#login")</td><td>Flexible attribute/class selection</td></tr>

<tr><td>XPath</td><td>By.xpath("//button[@id='login']")</td><td>Complex relationships and attributes</td></tr>

<tr><td>Link Text</td><td>By.linkText("Login")</td><td>Anchor elements acting as buttons</td></tr>

</table>

<hr>

<h2>92. Button Automation with Page Synchronization</h2>

<p>Modern applications frequently use AJAX, JavaScript, animations, and asynchronous API calls. Therefore, the presence of a button does not always mean that it is immediately ready for interaction.</p>

<pre><code>Page Load

   ↓

Button Added to DOM

   ↓

Button Becomes Visible

   ↓

Loading State Ends

   ↓

Button Becomes Enabled

   ↓

Button Becomes Clickable

   ↓

Selenium Click

   ↓

Application Action</code></pre>

<hr>

<h2>93. Practical Project: Login Button Testing</h2>

<p>Create an automation project for a login page containing username, password, and Login button.</p>

<h3>Test Scenarios</h3>

<ol>

<li>Verify Login button is displayed.</li>

<li>Verify Login button is enabled.</li>

<li>Verify Login button text.</li>

<li>Verify Login button type.</li>

<li>Click Login with valid credentials.</li>

<li>Click Login with invalid credentials.</li>

<li>Click Login with empty username.</li>

<li>Click Login with empty password.</li>

<li>Click Login with both fields empty.</li>

<li>Verify the resulting success or validation message.</li>

</ol>

<hr>

<h2>94. Practical Project: Registration Button Testing</h2>

<p>Automate a registration page and validate the Register button.</p>

<h3>Test Scenarios</h3>

<ul>

<li>Verify Register button visibility.</li>

<li>Verify Register button is initially disabled if required.</li>

<li>Enter mandatory fields.</li>

<li>Verify Register button becomes enabled.</li>

<li>Click Register.</li>

<li>Verify successful registration response.</li>

<li>Verify invalid data behavior.</li>

<li>Verify validation messages.</li>

</ul>

<hr>

<h2>95. Practical Project: E-Commerce Buttons</h2>

<p>Create an automation flow for an e-commerce application.</p>

<pre><code>Search Product

      ↓

Click Search

      ↓

Open Product

      ↓

Click Add to Cart

      ↓

Open Cart

      ↓

Click Checkout

      ↓

Enter Customer Details

      ↓

Click Continue

      ↓

Review Order

      ↓

Click Place Order

      ↓

Validate Order Confirmation</code></pre>

<hr>

<h2>96. Complete Button Automation Example</h2>

<pre><code>import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

 

public class ButtonAutomation {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://example.com/login");

 

        WebElement username = driver.findElement(By.id("username"));

        WebElement password = driver.findElement(By.id("password"));

 

        username.sendKeys("testuser");

        password.sendKeys("Test@123");

 

        WebDriverWait wait = new WebDriverWait(

            driver,

            Duration.ofSeconds(10)

        );

 

        WebElement loginButton = wait.until(

            ExpectedConditions.elementToBeClickable(

                By.id("login")

            )

        );

 

        System.out.println("Button Text: " + loginButton.getText());

        System.out.println("Button Enabled: " + loginButton.isEnabled());

 

        loginButton.click();

 

        driver.quit();

    }

}</code></pre>

<hr>

<h2>97. Button Automation Checklist</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Check</th><th>Status</th></tr>

<tr><td>Button locator identified</td><td>☐</td></tr>

<tr><td>Locator is stable</td><td>☐</td></tr>

<tr><td>Button is displayed</td><td>☐</td></tr>

<tr><td>Button enabled state verified</td><td>☐</td></tr>

<tr><td>Button text verified</td><td>☐</td></tr>

<tr><td>Button type verified</td><td>☐</td></tr>

<tr><td>Explicit wait added where required</td><td>☐</td></tr>

<tr><td>Button clicked successfully</td><td>☐</td></tr>

<tr><td>Expected result validated</td><td>☐</td></tr>

<tr><td>Exceptions handled appropriately</td><td>☐</td></tr>

</table>

<hr>

<h2>98. Interview Questions on Buttons</h2>

<h3>Q1. How do you click a button in Selenium?</h3>

<p>Locate the button using an appropriate locator and call the <code>click()</code> method.</p>

<pre><code>driver.findElement(By.id("login")).click();</code></pre>

<h3>Q2. How do you check whether a button is enabled?</h3>

<p>Use the <code>isEnabled()</code> method.</p>

<pre><code>boolean enabled = driver.findElement(By.id("submit")).isEnabled();</code></pre>

<h3>Q3. How do you check whether a button is visible?</h3>

<p>Use the <code>isDisplayed()</code> method.</p>

<h3>Q4. How do you get button text?</h3>

<p>Use the <code>getText()</code> method.</p>

<h3>Q5. How do you handle a button that appears dynamically?</h3>

<p>Use an appropriate explicit wait with a stable locator.</p>

<h3>Q6. What is the difference between visibility and clickability?</h3>

<p>Visibility means the element is displayed, while clickability generally requires the element to be visible and enabled and available for interaction under WebDriver's conditions.</p>

<h3>Q7. How do you handle a disabled button?</h3>

<p>Use <code>isEnabled()</code> to verify its state and perform the click only when the application makes it available for the intended test scenario.</p>

<h3>Q8. How do you handle a button inside an iframe?</h3>

<p>Switch to the iframe first, locate the button, interact with it, and then switch back to the default content when required.</p>

<h3>Q9. What causes ElementClickInterceptedException?</h3>

<p>It can occur when another element, such as an overlay, popup, or modal, prevents the intended button from receiving the click.</p>

<h3>Q10. When should JavaScript click be used?</h3>

<p>It can be used for special cases where normal WebDriver interaction cannot accomplish the intended interaction, but it should not automatically replace normal Selenium clicking.</p>

<hr>

<h2>99. Advanced Interview Questions</h2>

<h3>Q1. How would you automate a button that becomes enabled only after form validation?</h3>

<p>Enter the required values, wait for the button to become enabled or clickable, and then perform the click.</p>

<h3>Q2. How would you automate a button with dynamic text?</h3>

<p>Prefer stable attributes such as a unique ID, data attribute, or other reliable locator rather than depending on changing text.</p>

<h3>Q3. How do you handle a button covered by a loading overlay?</h3>

<p>Wait for the overlay to disappear and then wait for the button to become clickable.</p>

<h3>Q4. How do you handle a stale button?</h3>

<p>Re-locate the button after the DOM has changed instead of using the old WebElement reference.</p>

<h3>Q5. How do you validate that a button click worked?</h3>

<p>Verify an observable application result such as URL change, success message, modal appearance, page transition, changed element state, or another expected outcome.</p>

<hr>

<h2>100. Real-World Button Automation Flow</h2>

<pre><code>Requirement Analysis

        ↓

Identify Button

        ↓

Inspect HTML

        ↓

Select Stable Locator

        ↓

Find WebElement

        ↓

Check Page State

        ↓

Apply Explicit Wait

        ↓

Check Visibility

        ↓

Check Enabled State

        ↓

Click Button

        ↓

Wait for Application Response

        ↓

Validate Expected Result

        ↓

Capture Test Result

        ↓

Generate Report</code></pre>

<hr>

<h2>101. Button Automation Framework Structure</h2>

<pre><code>Automation Project

       ↓

Test Class

       ↓

Page Object

       ↓

Button Locator

       ↓

Reusable Click Method

       ↓

Explicit Wait

       ↓

Selenium WebDriver

       ↓

Browser

       ↓

Web Application</code></pre>

<hr>

<h2>102. Recommended Framework Utility</h2>

<pre><code>public class ButtonUtils {

 

    private WebDriver driver;

 

    public ButtonUtils(WebDriver driver){

        this.driver = driver;

    }

 

    public void click(By locator){

 

        WebDriverWait wait = new WebDriverWait(

            driver,

            Duration.ofSeconds(10)

        );

 

        WebElement button = wait.until(

            ExpectedConditions.elementToBeClickable(locator)

        );

 

        button.click();

    }

 

    public boolean isEnabled(By locator){

        return driver.findElement(locator).isEnabled();

    }

 

    public boolean isDisplayed(By locator){

        return driver.findElement(locator).isDisplayed();

    }

 

    public String getText(By locator){

        return driver.findElement(locator).getText();

    }

}</code></pre>

<hr>

<h2>103. Button Automation Best Practices Summary</h2>

<ul>

<li>Inspect the HTML before selecting a locator.</li>

<li>Prefer stable IDs and dedicated test attributes when available.</li>

<li>Use CSS selectors and XPath when required.</li>

<li>Use explicit waits for dynamic buttons.</li>

<li>Check button state when the application dynamically enables or disables it.</li>

<li>Use <code>click()</code> for normal browser interaction.</li>

<li>Do not immediately use JavaScript when a normal click fails.</li>

<li>Investigate overlays and synchronization issues.</li>

<li>Handle iframe and Shadow DOM boundaries correctly.</li>

<li>Validate the result after clicking.</li>

<li>Use Page Object Model for maintainable automation.</li>

<li>Create reusable button utilities in larger frameworks.</li>

<li>Keep destructive actions carefully controlled in test environments.</li>

</ul>

<hr>

<h2>104. Selenium Training Resource</h2>

<p>Buttons, forms, WebElements, locators, waits, browser interactions, TestNG, Page Object Model, and automation frameworks are important parts of Selenium WebDriver automation. You can explore the Selenium Automation Testing Course at JustAcademy for structured Selenium training and practical automation learning.</p>

<p><a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Explore Selenium Training at JustAcademy</a></p>

<hr>

<h2>105. Course Demo Registration</h2>

<p>To explore the course through a demo session, use the following registration link.</p>

<p><a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Selenium Course Demo</a></p>

<hr>

<h2>106. Conclusion</h2>

<p>Buttons are essential interactive elements in Selenium automation. Almost every important user workflow involves one or more buttons, including login, registration, search, save, update, delete, checkout, confirmation, and navigation.</p>

<p>To automate buttons effectively, a Selenium tester should understand locator strategies, the <code>click()</code> method, visibility and enabled states, explicit waits, dynamic elements, iframes, Shadow DOM, overlays, JavaScript interactions, exceptions, assertions, Page Object Model, and reusable automation methods.</p>

<p>A reliable button automation strategy does not stop at clicking the button. The test should also verify the expected result of that click. This approach helps create stable, maintainable, and meaningful Selenium automation scripts for real-world web applications.</p>

</div>

Previous Next
whatsapp