2
links = browser.find_elements_by_xpath("//h2[@class='result-firstline-title highlighted-domain-title']//a")
    results = []
    for i in range(len(links)):
        title = links[i].text()
        href = links[i].get_attribute("href")
        results.append(title)
        results.append(href)

So to sum this thing up, I made a "search bot" in selenium that opens google chrome and searches with ecosia. I then grabbed the links and sent them back into the results array. However I get this error, and it only displays on the title part

  File "c:/Users/icisr/OneDrive/Desktop/Bot/Searchbot.py", line 45, in get_results
    title = links[i].text()
TypeError: 'str' object is not callable

I then tried to only use links[i] but when I try to return it back it says that I cannot concatenate a string (href) with a web element (title)

str1 = ""
  for ele in results:
    str1 += ("  " + ele)
  return str1

3 Answers 3

2

text seems to not be a callable so just use

title = links[i].text
Sign up to request clarification or add additional context in comments.

Comments

0

text attribute

text is an attribute of a WebElement but not a method.

So you need to replace text() with text and your effective line of code will be:

title = links[i].text    

Comments

0

just replace text() with only text

title = links[i].text

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.