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.
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.
Comments