-2

I am trying to scrape a website which has some info under its div tag like this

<div> id="searchResults" class="multiple-view-elements"
<span>name</name>
<span>info</name>
<span>info</name>

<span>name</name>
......

My code

print ('-------------------------------------------------------------')
resp=driver.find_elements_by_id('searchResults').text
print (resp)
driver.quit()

it gives me this error

AttributeError: 'list' object has no attribute 'text'

What I'm doing wrong?

2
  • Refer this stackoverflow.com/q/49900117/4513879 myabe its help you Commented Dec 17, 2019 at 12:34
  • Thanks for replying, I already tried that didn't worked Commented Dec 17, 2019 at 12:38

2 Answers 2

1

Because you are using find_elements. which returns list of element and 'list' object don't have attribute/method 'text'

Use find_element e.g. resp=driver.find_element_by_id('searchResults').text to get the single element

Sign up to request clarification or add additional context in comments.

2 Comments

thanks man it worked also is there any way to find lement by class name
Yup. you can browse some good tutorial over the internet. techbeamers.com/locate-elements-selenium-python/…
0

You try to get the text attribute from the div elements, but there is no text contains for the element.

for example

<h3 class="LC20lb">Hi | Definition of Hi by Merriam-Webster</h3>

here the header h3 contains Hi | Definition of Hi by Merriam-Webster

so if you perform get text Method here you will get "Hi | Definition of Hi by Merriam-Webster",but your web element div has not text for contains attribute so get text is failed there.

so just clear your question what you wants to pint.

If any web element have text attribute or any contains text is there then you can try

String value= driver.findElement(By.id("")).getText();

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.