I wanted to get the Phone name ,description, price from the grid.
However getting the below error:
element = id.find_elements(By.XPATH("//div[contains(@class,'ProductModule__imageAndDescriptionWrapper')]")) TypeError: 'str' object is not callable
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(r"chromedriver.exe")
driver.get("https://www.tatacliq.com/apple/c-mbh12e00008")
id = driver.find_element_by_id('grid-container')
element = id.find_elements(By.XPATH("//div[contains(@class,'ProductModule__imageAndDescriptionWrapper')]"))
print(element)
for i in element:
print(i.get_attribute('a'))
CodePudding user response:
I guess it should be
element = id.find_elements(By.XPATH, "//div[contains(@class,'ProductModule__imageAndDescriptionWrapper')]")
CodePudding user response:
'a' isn't attribute but a tag. So you have to call href
as attribute
element = id.find_elements(By.XPATH("//div[contains(@class,'ProductModule__imageAndDescriptionWrapper')]"))
print(element)
for i in element:
print(i.a.get_attribute('href'))
#OR
element = id.find_elements(By.XPATH("//div[contains(@class,'ProductModule__imageAndDescriptionWrapper')]/a"))
print(element)
for i in element:
print(i.get_attribute('href'))