Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting text using Selenium
#4
Try find tag bye CSS selector or xPath.
Shorting class name did work for my,here a demo of both.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

#--| Setup
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1024,960")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
browser.get('file:///E:/div_code/scrape/local.html')
text = browser.find_element_by_class_name('explorer__titlesegment').text
text_selector = browser.find_elements_by_css_selector('body > span')[0].text
print(text)
print(text_selector)
Output:
Brokerage Account Brokerage Account
local.html that i test with.
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Title of the document</title>
  </head>
  <body>
    <span class="explorer__titlesegment explorer__titlesegment--type">Brokerage Account</span>
  </body>
</html>
Reply


Messages In This Thread
Getting text using Selenium - by WiPi - Apr-24-2020, 09:13 AM
RE: Getting text using Selenium - by snippsat - Apr-24-2020, 10:52 AM
RE: Getting text using Selenium - by WiPi - Apr-24-2020, 11:29 AM
RE: Getting text using Selenium - by snippsat - Apr-24-2020, 12:22 PM
RE: Getting text using Selenium - by WiPi - Apr-24-2020, 12:57 PM
RE: Getting text using Selenium - by snippsat - Apr-24-2020, 01:18 PM
RE: Getting text using Selenium - by WiPi - Apr-24-2020, 01:24 PM
RE: Getting text using Selenium - by snippsat - Apr-25-2020, 09:47 AM
RE: Getting text using Selenium - by WiPi - Apr-26-2020, 07:35 AM
RE: Getting text using Selenium - by snippsat - Apr-26-2020, 01:34 PM
RE: Getting text using Selenium - by WiPi - Apr-27-2020, 08:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  selenium wait for text question Larz60+ 3 2,578 Oct-25-2021, 09:50 AM
Last Post: Larz60+
  How to get specific TD text via Selenium? euras 3 8,861 May-14-2021, 05:12 PM
Last Post: snippsat
  Selenium extract id text xzozx 1 2,140 Jun-15-2020, 06:32 AM
Last Post: Larz60+
  Selenium returning web element instead of desired text newbie_programmer 1 5,226 Dec-11-2019, 06:37 AM
Last Post: Malt
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,658 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020