Home > OS >  Selenium webdriver NoSuchElementException s
Selenium webdriver NoSuchElementException s

Time:05-21

I know this question has been asked a million times before but as far as I can tell from those threads this code should be right so I would appreciate someone taking at look at it. The goal here is to create a bot that will buy an out of stock item when it returns but I am testing it on this. I am using JupyterLap and anaconda.

from selenium import webdriver as wd
import chromedriver_binary

wd.Chrome().implicitly_wait(60)

wd.Chrome().get("https://krikzz.com/our-products/cartridges/everdrive-gg-x7.html")

add_to_cart_button = wd.Chrome().find_element_by_xpath("/html/body/div[1]/main/section/div/div[2]/div[2]/form/div[4]/div[2]/button")

picture of error after running program

CodePudding user response:

You'd better use find_element_by_css_selector.

from time import sleep
from selenium import webdriver as wd
import chromedriver_binary

driver = wd.Chrome().implicitly_wait(60)

driver.get("https://krikzz.com/our-products/cartridges/everdrive-gg-x7.html")
sleep(5)

add_to_cart_button = driver.find_element_by_css_selector("button.card__button")

Hope it could help.

  • Related