Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
To get the text of a web element using Selenium, use the `WebElement` object's text Property. Here’s an example for the same:
from selenium import webdriver
# create a new Chrome browser instance
driver = webdriver.Chrome()
# navigate to a web page
driver.get("https://www.example.com")
# find an element by its CSS selector
element = driver.find_element_by_css_selector("#some-element")
# get the text of the element
text = element.text
# print the text
print(text)
# close the browser
driver.quit()
In this example, we first create a new Chrome browser instance using `webdriver.Chrome()`.Next, we navigate to a webpage using `driver.get()`. Then, we find an element on the page using `driver.find_element_by_css_selector()`, which takes a CSS selector as an argument. Finally, we get a text from that element by accessing its text property and printing it out before closing the browser with `driver.quit()`.
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud