Collect Information From Many Elements With Identic Class (selenium, Python)
I am trying to collect name and price from things in ebay. For example I searched 'armani', than I need to collect every item on first page using Selenium and append it to the list
Solution 1:
It sounds like you want to append tuples to the list of the form (name, price). Also you are attempting to iterate through a single web element when you want to iterate through a collection of web elements.
mylist = list()
for a in driver.find_elements_by_xpath(".//*[@id='item3aeba8d9f0']/div"): ##Change to .find_elements from .find_element
name = a.findElement(By.xpath(".//*[@id='item3aeba8d9f0']/div/div[2]/h3]")).getText()
price = a.findElement(By.xpath(".//*[@id='item3aeba8d9f0']/div/div[3]/div[2]/div/span[1]/span")).getText()
mylist.append((name, price)) // THE CHANGE IS HERE!!!
##or you instead of tuples you could do a two element list.
mylist.append([name, price]) // THE CHANGE IS HERE!!!
print(name)
Post a Comment for "Collect Information From Many Elements With Identic Class (selenium, Python)"