0

I tried to make an selenium app that scrapes the product name & price from a website, and send it to discord as a webhook. The error I get is in title.

product = driver.find_element_by_xpath("""//*[@id="details"]/h1""")
embed.add_field(name='Product:', value=str(product).text, inline=False)

Thats the line where I am getting the error. ^ But for example if I don't put .text it works on discord, but it doesn't give it as text and it shows like:

<selenium.webdriver.remote.webelement.WebElement (session="239269ee47dcdd86ba8f2ebb717ec15a", element="77b2212a-ccd4-4e5c-9a96-f0a931097a2d")>
Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

1

Your .text call should be on product, not your str() call, i.e.

embed.add_field(name='Product:', value=product.text, inline=False)
Badgy
  • 819
  • 4
  • 14
  • 1
    Yes, it is. That function call should be removed. – Badgy Apr 07 '20 at 22:43
  • I am getting this error now, ``` selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document (Session info: chrome=80.0.3987.149)``` – UnStuckX123 Apr 07 '20 at 22:44
  • According to [this](https://stackoverflow.com/questions/12967541/how-to-avoid-staleelementreferenceexception-in-selenium) it can happen if a DOM operation is causing it to be inaccessible. Try attempting it a couple of times as suggested in the post. – Badgy Apr 07 '20 at 22:48