0

I have a problem of whenever i want to click on an button element it does not trigger the event. In my case I am trying to add an item to the cart. A size needs to be clicked first before clicking the add to cart button. I am using chrome headless browser as well as the webdriver.

HTML of page

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import os

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = (r"C:\Users\dkael\AppData\Local\Google\Chrome SxS\Application\chrome.exe")

driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"),   chrome_options=chrome_options)
driver.get("https://www.nike.com/sg/launch/t/react-presto-undercover-white/")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//button[contains(text(),'US 10.5')]"))).click()
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class,'buying-tools-container')]//li[contains(@class,'selected')]")))
element = driver.find_element_by_xpath("//button[@class='ncss-brand ncss-btn-black pb3-sm prl5-sm pt3-sm u-uppercase u-full-width']")
element.send_keys(Keys.ENTER)
driver.save_screenshot("test.png")

print("success")

driver.quit()

I have tried this as well

WebDriverWait(driver, 20).until(EC.element_located_to_be_selected((By.XPATH,"//button[@class='ncss-brand ncss-btn-black pb3-sm prl5-sm pt3-sm u-uppercase u-full-width']"))).click()

I believe the error can be found here:

*PROJECT_CONFIG: Event key add-to-cart-clicked is not in datafile.", source: https://c.go-mpulse.net/boomerang/R6SH7-84RFL-GQQ8S-CW6MF-W5RWR*

1 Answers1

0

Why dont you use driver.find_element_by_link_text('ENTER_TEXT_HERE') ?

  • Thanks for the answer, but that didnt work as theres no link text to insert there. i have attached the html above. – Dave Loredo Feb 12 '20 at 19:50
  • What do you mean? The text is ADD TO BAG...could you send the link to the page? – Ton Lim Feb 12 '20 at 22:57
  • getting this error `selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"ADD TO BAG"} ` https://www.nike.com/sg/launch/t/react-presto-undercover-white/ Heres the link to the page – Dave Loredo Feb 13 '20 at 05:43