Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views1 page

Sauce Demo

The document is a Java program that automates the login process for the Sauce Demo website using Selenium WebDriver. It sets up the ChromeDriver, maximizes the browser window, and logs in with predefined credentials. After logging in, it searches for the 'Sauce Labs Backpack' product and clicks to add it to the cart.

Uploaded by

vikasbathe285
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Sauce Demo

The document is a Java program that automates the login process for the Sauce Demo website using Selenium WebDriver. It sets up the ChromeDriver, maximizes the browser window, and logs in with predefined credentials. After logging in, it searches for the 'Sauce Labs Backpack' product and clicks to add it to the cart.

Uploaded by

vikasbathe285
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package Base;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class sauceDemo {

public static void main(String[] args) {


// TODO Auto-generated method stub

System.setProperty("WebDriver.chrome.driver", "chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/v1/");

driver.manage().window().maximize();

driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.id("password")).sendKeys("secret_sauce");
driver.findElement(By.id("login-button")).click();

List<WebElement> obj = driver.findElements(By.tagName("a"));

for (WebElement product : obj) {


if (product.getText().equalsIgnoreCase("Sauce Labs Backpack")) {
product.click();
System.out.println("Selected product: " + product.getText());

driver.findElement(By.xpath("//button[@class='btn_primary
btn_inventory']"))
.click();
break;
}
driver.findElement(By.xpath("//button[@class='btn_primary
btn_inventory']"))
.click();

//for (WebElement objCurrentlink : obj) {


//String strLinkText = objCurrentlink.getText();
//System.out.println(strLinkText);

//}
}

You might also like