Issue
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'))
Solution
'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'))
Answered By - F.Hoque
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.