Looking to extract text from an h3 tag class with Python and selenium?

I am currently facing a challenge when it comes to extracting text from a specific webpage:

https://i.stack.imgur.com/YNo0Y.png

My attempts with

browser.find_element_by_class_name("W6bZuc.YMllz").text
have been unsuccessful.

I also tried

browser.find_element_by_tag_name("h3").text

but unfortunately, none of these methods returned the desired results. Are there any reliable ways to consistently retrieve the h3 element using selenium webdriver in python? Appreciate any guidance. Thank you.

Answer №1

Consider using textContent

browser.find_element_by_class_name("W6bZuc.YMllz").get_attribute("textContent")

Answer №2

Consider utilizing the .get_attribute('innerHTML') method:

driver.find_element_by_css_selector('.W6bZuc.YMllz').get_attribute('innerHTML')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I input a value that is not a URL (a URL without the http/https protocol) into the address bar of the Chrome browser using Selenium in Java?

I am facing a validation task where I need to input text in the address bar to redirect to a specific page. After that, I have to capture the current URL and compare it with the expected URL. Methods I've tested so far driver.get(https://www.google. ...

Why does Python Selenium's browser.find_element_by_class_name sometimes return an error?

Just starting out with Python and currently working through "Automate the Boring Stuff" by Al Swigart. I've created a script to play the popular game "2048" at "". After a few moves, the game will reach its maximum score and display a "Game Over!" me ...

The attempt to establish a connection to localhost/0:0:0:0:0:0:0:1:1731 using ChromeDriver Chrome with Selenium Java in Spring Bot resulted in a java.net.ConnectException

I have a web application built with Selenium and Spring Boot running on a Google Cloud VM Instance. Here are the versions I am using: Spring Boot - 2.0.0.RELEASE Selenium - 3.9.1 Linux - Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux Chrome Driver - 2. ...

Mistakes in Syntax: If, Elif, and Else Statements

Greetings to whoever comes across this message. I am currently struggling with a semantic error that seems to have me stumped. As someone who is new to the world of coding, I am trying my hand at learning Python 3. My goal is to create a code that informs ...

Exploring the Contrast Between "Wait until Visible" and "Wait until Located" Commands in Selenium

When utilizing both wait(until.elementLocated(element, timeout)) and wait(until.elementVisible(element, timeout)), I have noticed that the 'wait until visible' method fails in certain scenarios where the 'wait until located' method does ...

Stop child classes from running inherited test methods

I currently have two functional test classes set up for testing. class VehicleTest(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() def test_math(self): self.assertEqual(1+1, 2) class VehicleTestCa ...

Although Actions allow for selecting elements, they do not support dragging elements to a specific location, as the drop functionality is triggered on hover

Link to the URL - System.setProperty("webdriver.chrome.driver", "D:\\Eclipse\\Files\\chromedriver_win32\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().window().fullscreen(); ...

Retrieve the total count of rows present in a specific table

Is there a way to accurately determine the number of rows in a table? I've attempted multiple methods (all unsuccessful) and this is my latest attempt: var _tableOfInterestsCount = wait.Until(x => x.FindElements(By.XPath("//*[@id='gridBody ...

Encountering an authorization issue when trying to execute "pip

I am currently facing an issue with installing selenium 3 on my Mac using the default Python located at /usr/bin/python. Whenever I attempt to install it by running https://pypi.org/project/selenium/ through command pip install selenium, I encounter an err ...

"Tracking the current value of Tesla's stock through their

I am completely new to Python and I'm trying to find a way to retrieve the current stock price of TESLA. The program I have at the moment is displaying too much information. I am using Python 3 on a school computer connected through Linux. Unfortunat ...

Discrepancy in Results: Selenium and Beautiful Soup Showing Varied len() Outputs when Scraping the Same Website (Amazon)

After running the code snippet below multiple times, I noticed that the output of print(len(block1)) varied each time. I'm struggling to identify the root cause of this fluctuation: my implementation, the way Selenium loads pages, a potential anti-s ...

Retrieve the border color using Selenium WebDriver

Hey everyone, I'm currently trying to retrieve the border color of an extjs 4.2 form control text field using the getCssValue method. However, I'm having trouble getting the value as it's coming back blank. Below is a sample of my code that ...

Learn how to implement Data-driven testing in Selenium using Excel or Numbers on a Mac device!

On my Mac machine, I am utilizing Selenium for testing. However, when it comes to data-driven testing using Excel, how can this be done on a Mac since it doesn't have Excel but uses "Numbers" instead, which is similar? ...

Struggling to use XPath to interact with a pop-up window in Selenium

Is there a way to retrieve 'CIK' codes from the 'SEC' using Selenium? When I try running the code, a "survey" pop-up appears that doesn't show up when doing it manually. This causes issues with my code because I can't inspect ...

RSelenium: What is preventing me from inputting a password into this (Java?) login form?

In the midst of my web scraping endeavors, I have encountered a slight hiccup when trying to extract data from this particular website using RSelenium. While I've had success sending text to various elements on the page, the login field has proven to ...

Executing automated tests with Crontab using Selenium FirefoxDriver

My Debian server is set up and I'm looking to automate tests regularly using crontab or another method for daily execution. I am utilizing Selenium WebDriver 2.45.0 Java Libraries for this task. When running the script via command line, I can succes ...

Executing close() function after all tests in ScalaTest with Selenium have finished running

I currently have several scala tests running, but I am unsure of how to properly close or quit the webdriver once the test run is complete. I know about beforeAndAfterAll, but it seems to act on each test class individually, while I only want to close the ...

The method of Tridiagonal Matrix Algorithm implemented with Numba's nopython mode

I've been attempting to develop a TDMA algorithm using numba in nopython mode. Take a look at my code below: @jit(nopython=True) def TDMA(a,b,c,d): n = len(d) x = np.zeros(n) w = np.zeros(n) # ac, bc, cc, dc = map(np.copy, (a, b, c, d)) # c ...

How can we use Python and Selenium to retrieve the text from HTML that includes the <p> tag?

I have a simple question that I hope you can help me with. I'm not feeling well and struggling to complete my presentation because my brain just isn't functioning properly. Here is the HTML code in question: <p> <b>Postal code:& ...

Calculating the total cumulative amount from a list of Map

I recently encountered a scenario where I received input containing a list with maps inside it. List<Map<String, String>> actAllSavAccDetLists = test1Page.getAllSavingsAccountsDetails(); // The data looks something like this [ {Savings=Ac ...