0

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'))

enter image description here

2 Answers 2

1

'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'))
Sign up to request clarification or add additional context in comments.

5 Comments

yes got it thanks. just a one change in syntax suggested by @sudden_appearance
However this code is not working in --headless mode, do you have any idea why ?
To evade detection you have to use open mode , otherwise headless mode is showing bot detection as a result getting error
open as in which mode ?
open mode means default, you don't do nothing meaning if you don't use -- headless then it's called open mode. Thanks
1

I guess it should be

element = id.find_elements(By.XPATH, "//div[contains(@class,'ProductModule__imageAndDescriptionWrapper')]")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.