Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created December 17, 2024 16:06
Show Gist options
  • Save borodicht/6b725348dc28a382afca02d8aead9fa6 to your computer and use it in GitHub Desktop.
Save borodicht/6b725348dc28a382afca02d8aead9fa6 to your computer and use it in GitHub Desktop.
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class ProductsPage {
WebDriver driver;
By title = By.cssSelector("[data-test=title]");
String addToCartPattern = "//div[text()='%s']//ancestor::div[@class='inventory_item']//button";
public ProductsPage(WebDriver driver) {
this.driver = driver;
}
public String getTitle() {
return driver.findElement(title).getText();
}
public void addToCart(String product) {
driver.findElement(By.xpath(String.format(addToCartPattern, product))).click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment