Selecting Multiple buttons on a page in Selenium Python

  html, python, selenium, selenium-webdriver, xpath

Ok so I am having this issue with selecting all of the red Cupon Buttons on this SafeWay website. I have tried going by class, name, xpath, you name it. I am just trying to click all of the buttons that say "Clip Cupon"

You need a sign up, but here is the code without my sign-ininformation and user.

from selenium import webdriver
import random
import string
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
#find the path for the driver
driver = webdriver.Chrome(executable_path="C:UsersUSERDownloadschromedriver_win32chromedriver.exe")
driver.get("https://www.safeway.com/account/sign-in.html?goto=/justforu/coupons-deals.html")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="label-email"]'))
    )
except:
    driver.quit()
signinlink=driver.find_element_by_xpath('//*[@id="label-email"]')
signinlink.click()
sW_Email = driver.find_element_by_id('label-email')
sW_Email.send_keys('XXXXXXXXXX')
sW_Email1= driver.find_element_by_xpath('//*[@id="label-password"]')
sW_Email1.send_keys("XXXXXXXXXX")
sW_Button=driver.find_element_by_xpath('//*[@id="btnSignIn"]')
sW_Button.click()
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, '/html/body/div[2]/div/div/div[1]/div/div/div/div/div[3]/div[2]/div[1]/div/div/div[2]/a/img'))
    )
except:
    driver.quit()
like = driver.find_elements_by_class_name("btn grid-coupon-btn btn-default")
for x in range(0,len(like)):
    if like[x].is_displayed():
        like[x].click()
        print("If you can see this it Ran")
    else:
        pass

Source: Python Questions

LEAVE A COMMENT