Check whether the Promocode has applied and the text is displayed

 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.add_argument('--disable-web-security') # to avoid CORS issue
chrome_options.add_experimental_option("detach", True) # to retain the browser
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) # As the list will take time to load

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

count = len(products)

for product in products:
product.find_element(By.XPATH, "div/button").click()

driver.find_element(By.CSS_SELECTOR, "img[alt='Cart']").click()
driver.find_element(By.XPATH, "//button[text()='PROCEED TO CHECKOUT']").click()
# Sum validation
prices=driver.find_elements(By.XPATH,"//tr/td[5]/p")
sum=0
for price in prices:
sum=sum+ int(price.text)

print(sum)
totalAmount = int(driver.find_element(By.CSS_SELECTOR,".totAmt").text)
print(totalAmount)
assert sum == totalAmount
#with CSS SELECTOR it can be written as
#tr td:nth-child(5) p

driver.find_element(By.CSS_SELECTOR, ".promoCode").send_keys("rahulshettyacademy")
driver.find_element(By.CSS_SELECTOR, ".promoBtn").click()
wait= WebDriverWait(driver,10)
wait.until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR,".promoinfo")))

print(driver.find_element(By.CLASS_NAME, "promoInfo").text)

Comments

Popular posts from this blog

accessing frame through selenium and switching back to the original content

Assertion to check that the text is not displayed when Hide button is clicked

Running javascript commands inside a python file through selenium