Assert the expected names are displayed on the webpage for products

 import time


from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

chrome_options = Options()
#chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-web-security')
chrome_options.add_experimental_option("detach", True)

exPdcts=["Cucumber - 1 Kg","Raspberry - 1/4 Kg","Strawberry - 1/4 Kg"]
actualList=[]
service_obj= Service("C://Users//ancha//chromedriver_win32(4)//chromedriver.exe")


driver = webdriver.Chrome(service=service_obj, options=chrome_options)
driver.implicitly_wait(2)
driver.get("https://www.rahulshettyacademy.com/seleniumPractise")


driver.find_element(By.CSS_SELECTOR, ".search-keyword").send_keys("ber")
time.sleep(2)

products = driver.find_elements(By.XPATH, "//div[@class='products']/div")

for product in products:
actualList.append(product.find_element(By.XPATH,"h4").text)

print(actualList)
print(exPdcts)

assert actualList == exPdcts

Comments

Popular posts from this blog

Get the test from a child window and then switch back to parent window and check if the text is right