1. Navigate to [Link]
com/
import time
from selenium import webdriver
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
[Link](5000)
[Link]()
2. a. Try to login with a locked-out user [locked_out_user/
secret_sauce].
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('locked_out_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
[Link](5000)
b. Validate the error message on the screen.
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('locked_out_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
[Link](5000)
3. [Link] with a valid username and password [standard_user/
secret_sauce].
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('standard_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
[Link](500)
[Link]()
[Link] login is successful.
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('standard_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
driver.find_element([Link], 'inventory_container')
print("login successful")
[Link](500)
[Link]()
1. Assert that the product- “Dummy Product” is not present in
the product list.
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('standard_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
driver.find_element([Link], 'inventory_container')
print("login successful")
products = driver.find_elements(By.CLASS_NAME, 'inventory_item_name')
product_names = [[Link] for product in products]
assert "Dummy Product" not in product_names, "Dummy Product should not be in the product
list."
print("Assertion passed: 'Dummy Product' is not present in the product list.")
[Link](5000)
[Link]()
5. a. Assert that the product “Sauce Labs Bolt T-Shirt" is present
in the product list.
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('standard_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
driver.find_element([Link], 'inventory_container')
print("login successful")
products = driver.find_elements(By.CLASS_NAME, 'inventory_item_name')
product_names = [[Link] for product in products]
assert "Sauce Labs Bolt T-Shirt" in product_names, "Sauce Labs Bolt T-Shirt is not present in the
product list."
print("Assertion passed: 'Sauce Labs Bolt T-Shirt' is present in the product list.")
[Link](5000)
[Link]()
5. b. If the product is found, grab the price of the product and print
it in the console.
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('standard_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
driver.find_element([Link], 'inventory_container')
print("login successful")
products = driver.find_elements(By.CLASS_NAME, 'inventory_item')
for product in products:
product_name = product.find_element(By.CLASS_NAME, 'inventory_item_name').text
if product_name == "Sauce Labs Bolt T-Shirt":
price = product.find_element(By.CLASS_NAME, 'inventory_item_price').text
print(f"Price of '{product_name}': {price}")
[Link](5000)
[Link]()
6. a. Add this product and any other product to the cart and
navigate to the cart.
import time
from selenium import webdriver
from [Link] import By
driver= [Link]()
driver.maximize_window()
[Link]("[Link]
driver.find_element([Link], 'user-name').send_keys('standard_user')
driver.find_element([Link], 'password').send_keys('secret_sauce')
driver.find_element([Link], 'login-button').click()
driver.find_element([Link], 'inventory_container')
print("login successful")
products = driver.find_elements(By.CLASS_NAME, 'inventory_item')
sauce_labs_bolt_tshirt = None
other_product = None
for product in products:
product_name = product.find_element(By.CLASS_NAME, 'inventory_item_name').text
if product_name == "Sauce Labs Bolt T-Shirt":
sauce_labs_bolt_tshirt = product
elif not other_product:
other_product = product
if sauce_labs_bolt_tshirt:
sauce_labs_bolt_tshirt.find_element(By.CLASS_NAME, 'btn_inventory').click()
print("Added 'Sauce Labs Bolt T-Shirt' to the cart.")
else:
print("'Sauce Labs Bolt T-Shirt' not found.")
if other_product:
other_product.find_element(By.CLASS_NAME, 'btn_inventory').click()
print("Added another product to the cart.")
else:
print("No other products found to add to the cart.")
# Navigate to the cart
driver.find_element([Link], "[Link]()-t-shirt-(red)").click()
print("Navigated to the cart page.")
[Link](5000)
[Link]()