Search a item using selenium webdriver

Testing steps:

  1. Load the page using the given URL (Log in | Register (formsscasb.tk))
  2. Login using valid credentials → (Email: radhika.rakesh@jobinandjismi.com, Password: test@12345)
  3. Select the search icon
  4. Enter an item into the search field → (62-058 High Yield MICR Toner Cartridge: HP LaserJet M506x)
  5. Select the Go button
  6. View and select the product to view the PDP page
  7. Get the title of the page
  8. Put a condition in order to check whether the test is passed or not

Code:

public static void main(String[] args) throws Exception {

WebDriverManager.chromedriver().setup();

ChromeOptions options = new ChromeOptions();

options.addArguments(“start-maximized”);

WebDriver driver = new ChromeDriver(options);

driver.get(“https://www.formsscasb.tk/Formsscasb/Formsscasb/checkout.ssp?is=login&loginParam=false&login=T&fragment=login-register#login-register“);

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.findElement(By.id(“login-email”)).sendKeys(“radhika.rakesh@jobinandjismi.com“);

driver.findElement(By.id(“login-password”)).sendKeys(“test@12345”);

driver.findElement(By.className(“login-register-login-submit”)).click();

Thread.sleep(5000);

driver.findElement(By.className(“site-search-button-link”)).click();

driver.findElement(By.xpath(“//input[@class=’itemssearcher-input typeahead tt-input’]”)).sendKeys(“62-058 High Yield MICR Toner Cartridge: HP LaserJet M506x”);

driver.findElement(By.className(“site-search-button-submit”)).click();

Thread.sleep(3000);

driver.findElement(By.xpath(“//span[@itemprop=’name’][contains(text(),’62-058′)]”)).click();

Thread.sleep(3000);

System.out.println(“Title of the page : “+driver.getTitle());

Thread.sleep(3000);

if (driver.getTitle().equals(“62-058 High Yield MICR Toner Cartridge: HP LaserJet M506x”)) {

System.out.println(“Test Passed”);

}

driver.quit();

}

Leave a comment

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