I am using wait method
to find element but they give me empty output. What is the mistake?
link https://www.amazon.co.uk//dp/B094FZ1XFJ
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
PATH="C:\Program Files (x86)\chromedriver.exe"
url='https://www.amazon.co.uk//dp/B094FZ1XFJ'
driver =webdriver.Chrome(PATH)
driver.get(url)
item = dict()
try:
about_this_item_list = []
about_this_item_divs = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@id='featurebullets_feature_div']//ul//li//span")))
for div in about_this_item_divs:
about_this_dict = dict()
about_this_dict['about_this_item'] = div.text
about_this_item_list.append(about_this_dict)
item['about_this_item'] = about_this_item_list
except:
item['about_this_item'] = ''
print(item)
CodePudding user response:
This should be visibility_of_all_elements_located()
which returns list of elements.
about_this_item_divs = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@id='featurebullets_feature_div']//ul//li//span")))
This will returns only web element NOT list of web elements.
about_this_item_divs = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@id='featurebullets_feature_div']//ul//li//span")))
UPdate:
It seems you need to scroll the page to get element visible.
Try with presence_of_all_elements_located()
about_this_item_divs = WebDriverWait(driver, 20).until(EC.presence_of_all_elements_located((By.XPATH, "//div[@id='featurebullets_feature_div']//ul//li//span")))
OutPut:
{'about_this_item': [{'about_this_item': 'Innovative design: Our clever car boot liners for dogs have been designed to be fully adaptable. The cover features a unique armrest pass-through and can be used with the back seats up, on a 60/40 split, a 40/60 split, a 40/20/40 split, or folded down all the way.'}, {'about_this_item': 'All-round protection: This multipurpose car boot liner shields your car from mud, dirt, fur, paw prints, spills, and more! It features extra high side panels with hook and loop fastenings to help keep the upholstery of your car in great condition.'}, {'about_this_item': 'Scratch- & slip-proof: Thanks to the non-slip backing and seat anchors, the boot cover for dogs stays put even on the ruffest rides! Worried your pup is going to scratch your boot or doors? Don’t be, our padded boot protector is completely claw- and scratch-proof.'}, {'about_this_item': 'Easy-care: Our waterproof dog car boot covers for cars protect your boot stays from unpleasant accidents or spills. The car boot cover is easy to spot clean with a damp cloth and can even be thrown into the washing machine on the gentle cycle!'}, {'about_this_item': ''}]}