0

I am having issues accessing the text saying '-175'.

website html (not sure how to post the screenshot!)

I failed when trying this:

driver.find_element_by_xpath('//div[@class="my-bets-history-possible-win ng-hide"]/span[2]').text

I have also enabled the disabled parts of the html by using this:

button = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//input[@class="second-color ng-pristine ng-untouched ng-valid ng-not-empty"]')))
driver.execute_script('arguments[0].removeAttribute("disabled");', button)

Any further ideas?

1 Answers1

0

To extract the text -175 ideally you need to induce WebDriverWait for the presence_of_element_located() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR and text attribute:

    print(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.my-bets-history-possible-win.ng-hide span::nth-of-type(2)"))).text)
    
  • Using XPATH and get_attribute("innerHTML"):

    print(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@class="my-bets-history-possible-win ng-hide"]//following::span[2]"))).get_attribute("innerHTML"))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

You can find a relevant discussion in How to retrieve the text of a WebElement using Selenium - Python


References

Link to useful documentation:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • This unfortunately doesn't work. The text '-175', is not actually visible on the webpage which leads me to believe that it has been disabled. Furthermore, does get_attribute() work here as the text is not from an attribute, it is currently stored as text, right? – rngaebzzbz Mar 07 '22 at 16:11
  • Checkout the updated answer and let me know the status. – undetected Selenium Mar 07 '22 at 16:33
  • yep, the following imports had already been added. Did you update with anything else? – rngaebzzbz Mar 07 '22 at 17:27
  • I think the solution may be in changing the html from "my-bets-history-possible-win ng-hide" to "my-bets-history-possible-win". Is there a way to do this? (I did it manually and I could find it using .text – rngaebzzbz Mar 07 '22 at 17:36
  • @rngaebzzbz The fact is you have shared an image of the HTML which doesn't helps in testing the solution. A text based HTML would have helped. – undetected Selenium Mar 07 '22 at 18:45