Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created April 29, 2026 18:45
Show Gist options
  • Select an option

  • Save borodicht/68d9501ddfaa21c5ea062db459e47dc4 to your computer and use it in GitHub Desktop.

Select an option

Save borodicht/68d9501ddfaa21c5ea062db459e47dc4 to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.time.Duration;
public class AddAndRemoveElements {
WebDriver driver;
@BeforeMethod
public void setup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@Test
public void checkAddElements() {
driver.get("https://the-internet.herokuapp.com/add_remove_elements/");
driver.findElement(By.xpath("//button[text()='Add Element']")).click();
driver.findElement(By.xpath("//button[text()='Add Element']")).click();
int countDelete = driver.findElements(By.xpath("//button[text()='Delete']")).size();
Assert.assertEquals(countDelete, 2);
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment