from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
browser = webdriver.Chrome("/Users/mymac/Documents/AutoFill/chromedriver")
browser.get("https://www.jcpenney.com/p/a-n-a-skinny-denim-ankle-crop-jeans/ppr5007199315?pTmplType=regular&catId=cat100250096&deptId=dept20000013&urlState=/g/womens-jeans/N-bwo3xD1nopgw&badge=onlyatjcp")
cart = browser.find_element_by_class_name('button')
time.sleep(5)
cart.click()
这基本上是将一个项目添加到我的购物车(“购物车”是添加到购物车按钮)。但是,每当我运行它时,我的最后一行都会出错:
错误:selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见
以下是网站上的HTML:
来自网站的HTML;突出显示的蓝色部分指的是我要点击的按钮
感谢您的帮助!
答案 0 :(得分:0)
看到你有警报,尺寸范围,sizenumber,然后点击添加到包按钮和颜色我保持defaut黑色
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
browser = webdriver.Chrome("/Users/mymac/Documents/AutoFill/chromedriver")
browser.maximize_window()
selectsizerange = input("Enter SIZE RANGE")
sizenumber = input("ENTER SIZE NUMBER")
browser.get("https://www.jcpenney.com/p/a-n-a-skinny-denim-ankle-crop-jeans/ppr5007199315?pTmplType=regular&catId=cat100250096&deptId=dept20000013&urlState=/g/womens-jeans/N-bwo3xD1nopgw&badge=onlyatjcp")
time.sleep(5)
browser.switch_to_active_element()
browser.find_element_by_id('closeButton').click()
time.sleep(3)
browser.find_element_by_id('SIZE_RANGE').send_keys(selectsizerange)
browser.find_element_by_id('SIZE').send_keys(sizenumber)
browser.find_element_by_css_selector("ul#COLOR li:nth-child(1) > img").click()
time.sleep(3)
browser.find_element_by_css_selector("div.pp__cta__all > div:nth-child(1) > button").click()