How to extract text from Selenium Object?

Brandon Jacobson

My code logs into my Fidelity account and then finds an element. I'm able to find the Selenium object, but I want to extract the text in it which contains my portfolio balance. When I print the object, the code works fine, but I'm unable to get the text or the balance from it.

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


def fidelity_check():
    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option("detach", True)
    # options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Users\Notebook\Documents\chromedriver.exe')
    driver.get("https://www.fidelity.com/")
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userId-input"))).send_keys(
        "MYUSERID")
    driver.find_element_by_css_selector("input#password").send_keys("MYPASSWORD")
    driver.find_element_by_css_selector("button#fs-login-button").click()

    try:
        element_present = EC.presence_of_element_located((By.XPATH, '// *[ @ id = "tabContentSummary"]'))
        WebDriverWait(driver, 10).until(element_present)
        print(element_present)
    except TimeoutError:
        print("Page Not Loaded.")

This is the result: selenium.webdriver.support.expected_conditions.presence_of_element_located object at 0x035EFE10

Here is the inspect element results:

<span class="ledger--section-total js-total-balance-value">$X.XX</span>

I tried the following and it doesn't work.

element_present.text()
# And I tried:
element_present.text

Neither work.

SeleniumUser002

please try below solution

amount = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id = "tabContentSummary"]//span')))
print(amount.text)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract text from an unordered list with selenium

How to extract text from text nodes through Selenium?

How to extract text from child Text Nodes - Selenium

How to extract text from svg using python selenium

How to extract the text from the HTML using Selenium and Python

How to extract the text $7.56 from the webpage using Selenium through Python

Python/Selenium - how to extract text from modal fade content?

How to extract text from previously inserted input with Selenium?

How i extract text from a model dialog in selenium?

How to extract text from div class using Selenium with Python

How to extract the text from the element using Selenium through Java

How to extract the text from the webelements using Selenium and Python

How can I extract the text from a webelement using selenium

How to extract text from TextNode using Selenium in VBA

How to extract the text from the parent node excluding the text from the child node using Selenium

Selenium Python - Extract Text from Class

Extract text from webpage using Selenium in Python

Python and how to get text from Selenium element WebElement object?

How to get text object from a html table using selenium python

How to extract the text 5 from the text node within the parent div node using Selenium and Python

How to extract multiple text using selenium python

How to extract the text elements using Selenium in Python?

How to extract text that is wrapped in \t and \n in selenium

How to extract text if selenium returns empty tags?

How to extract text from a WebPage

How to extract countries from a text?

How to extract text from string?

How to extract date from the text

How to extract units from text

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive