Interact with WebElements

Rate this post

webelement

Interact with a button

<code lang="java">
package book.chapter05;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import book.chapter09.tests.DriverBase;

public class InteractWithButton extends DriverBase {

  @BeforeMethod
  public void setUp() {
    driver.get("http://techblog.polteq.com/testshop/");
  }

  @Test
  public void interactButton() {
    WebElement button = driver.findElement(By
        .id("submitMessage"));
    button.click();
  }

}
</code>

Interact with a textfield

<code lang="java">
package book.chapter05;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import book.chapter09.tests.DriverBase;

public class InteractWithTextField extends DriverBase {
  
  @BeforeMethod
  public void setUp() {
    driver.get("http://techblog.polteq.com/testshop/");
  }
  
  @Test
  public void interactTextfield() {
    WebElement emailTextfield = driver.findElement(By.id("email"));
    emailTextfield.click();
  }

}
</code>

One thought on “Interact with WebElements”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.