Skip to content
Advertisement

How to extract text from div class using Selenium with Python

I am trying to create a bot to pay some bills automatically. The issue is I can’t extract the amount(text) under div class. The error is element not found. Used driver.find_element_by_xpath and WebDriverWait. Can you please indicate how to get the highlighted text-see the attached link? Thanks in advance.Page_inspect

Advertisement

Answer

I believe there was some issue with your xpath. Try below it should work:

amount = WebDriverWait(self.driver, self.timeout).until( EC.presence_of_element_located((By.XPATH, '//div[starts-with(@class,"bill-summary-total")]//div[contains(@data-ng-bind-html,"vm.productList.totalAmt")]'))) 
print('Your amount is: {}'.format(amount.text)) 
return float(amount.text) 
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement