我正在玩Python和webdriver,我正在使用下面的代码。
我正在尝试点击“查看全部”选项以列出页面上的所有产品,我可以点击显示可用选项的向下箭头,但我无法点击“查看全部”选项,任何人都有任何想法我做错了什么?
它只是说找不到第二个元素。
driver = webdriver.Firefox()
driver.get('http://www.boots.ie/webapp/wcs/stores/servlet/SearchDisplay?categoryId=&storeId=11353&catalogId=28502&langId=-1&sType=SimpleSearch&resultCatEntryType=2&showResultsPage=true&searchSource=Q&pageView=&beginIndex=0&pageSize=24&manufacturer=lynx&isA2ZBrand=Y')
element = driver.find_element_by_xpath("//div[contains(@class, 'select_order')]/table")
element.click()
element = driver.find_element_by_xpath("//div[contains(@class, 'select_order')]/div[contains(@class, 'dijitSearchResultSelectSizeLabel')]")
element.click()
答案 0 :(得分:0)
尝试添加wait.until
语句,如下所示:
driver = webdriver.Firefox()
# Create wait element to be used later
# 10 represents the amount of seconds to wait before throwing TimeoutException
wait = ui.WebDriverWait(driver, 10)
driver.get('http://www.boots.ie/webapp/wcs/stores/servlet/SearchDisplay?categoryId=&storeId=11353&catalogId=28502&langId=-1&sType=SimpleSearch&resultCatEntryType=2&showResultsPage=true&searchSource=Q&pageView=&beginIndex=0&pageSize=24&manufacturer=lynx&isA2ZBrand=Y')
element = driver.find_element_by_xpath("//div[contains(@class, 'select_order')]/table")
element.click()
# Wait for element to pop up
wait.until(lambda driver: driver.find_element_by_xpath('//div[contains(@class, 'select_order')]/div[contains(@class, 'dijitSearchResultSelectSizeLabel')]'))
# Element popped up, now select & click it
element = driver.find_element_by_xpath("//div[contains(@class, 'select_order')]/div[contains(@class, 'dijitSearchResultSelectSizeLabel')]")
element.click()
答案 1 :(得分:0)
以下是您的问题的答案:
要点击View all
选项列出页面上的所有产品,点击显示可用选项的向下箭头后,您可以使用该元素的id
点击它如下:
element = driver.find_element_by_id("dijit_MenuItem_1_text")
element.click()
如果这回答你的问题,请告诉我。