问题陈述: - 在http://www.saksoff5th.com/laurel-nubuck-leather-belt/0492184735210.html?start=2&cgid=Men#q=belts&start=1&location=0&slotLoads=1网站上,我正在尝试添加尺寸并为商品选择颜色,以便我可以继续结帐。但是,我收到错误list index out of range
。我的代码是:
selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Firefox()
#Searches via Belts in the text box
browser.get('http://www.saksoff5th.com')
browser.find_element_by_id('q').send_keys('Belts' + Keys.RETURN)
#Clicks the Men link
browser.implicitly_wait(10)
browser.find_element_by_link_text('Men').click()
time.sleep(10)
elemprodcl = browser.find_element_by_id('search-result-items')
Listprdcl= elemprodcl.find_elements_by_class_name('grid-tile')
elemprodcl2 = Listprdcl[1].find_element_by_class_name('product-tile')
elemprodcl3 = elemprodcl2.find_element_by_class_name('product-image')
elemprodcl4 = elemprodcl3.find_element_by_tag_name('a')
elemprodcl4.find_element_by_tag_name('img').click()
elemproddl = browser.find_element_by_class_name('swatches')
print('yes')
Listproddl = elemproddl.find_elements_by_class_name('selectable')
print('yes1')
Listproddl[1].click()
print('yes2')
elemclr = browser.find_element_by_class_name('Color')
print('yes3')
Listclr = elemclr.find_elements_by_class_name('selectable')
print('yes4')
Listclr[0].find_element_by_class_name('swatchanchor').click()
print('yes5')
Output as
yes
yes1
yes2
yes3
yes4
Traceback (most recent call last):
File "C:\Python27\Off5th_Guest_Checkout", line 56, in <module>
Listclr[0].find_element_by_class_name('swatchanchor').click()
IndexError: list index out of range