You need to access the page_source property:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://example.com")
html_source = browser.page_source
if "whatever" in html_source:
# do something
else:
# do something else
Answer from AutomatedTester on Stack OverflowSelenium Python
selenium-python.readthedocs.io
Selenium with Python — Selenium Python Bindings 2 documentation
1.2. Installing Python bindings for Selenium · 1.3. Instructions for Windows users · 1.4. Installing from Git sources · 1.5. Drivers · 1.6. Downloading Selenium server · 2. Getting Started · 2.1. Simple Usage · 2.2. Example Explained · 2.3. Using Selenium to write tests ·
Top answer 1 of 9
267
You need to access the page_source property:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://example.com")
html_source = browser.page_source
if "whatever" in html_source:
# do something
else:
# do something else
2 of 9
19
Use:
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()
html_source_code = driver.execute_script("return document.body.innerHTML;")
html_soup: BeautifulSoup = BeautifulSoup(html_source_code, 'html.parser')
Now you can apply Beautiful Soup functions to extract data...
Python: how i can print all the source code by using Selenium - Stack Overflow
driver.page_source don't returns all the source code.It is detaily printing only some parts of code, but it's missing a big part of code. How can i fix this? This is my code: from selenium import More on stackoverflow.com
Python Selenium - source code reading
Hello! I’ve a problem - I need to find element by class (let’s say class=“hello”) and Selenium Python reads this source code from the top to the bottom - how can I reverse it? How to make Selenium read this code from the bottom () to the top ()? The element with that class I’m looking ... More on forum.freecodecamp.org
Selenium + Python, need advice on how to approach unit testing
Personally I don't like asserts. But did you verify that that URL string you're asserting is what login_page.get_url() is returning exactly?
For my automation at work, I don't use asserts. Built out classes which handle intake of the test scripts and custom error handling on the lines themselves. Everything goes through a try/except block and reports the line, screenshot, and comments from the script in the error. Which, is what an assert does.
More on reddit.comWhich is the best way to use Selenium? [Newbie]
I believe that without learning how to program your tests will be hard to maintain and very fragile. The reason for this is that any IDE (or recorder) will not reuse code or generalize on its own. That being said, the IDE may be a good starting point if you look at the underlying code generated and learn from it. If you are going to program yourself, use the same programming language the developers on your team use. Selenium has bindings for most popular programming languages. The reason for this is that the developers will be able to help you with the more complex code and help maintain the code base for the tests. If you have not already done this, prioritize your manual tests according to importance/value, start by automating high value tests that require the least amount of work (an example, login page or search engine). Instead of automating everything at the outset, try to make those few high valued tests as stable as possible (this means generalizing, for example by using the page object pattern and maintaining them as the project evolves). The fallowing are good lectures on how to use Selenium and how to build an automation framework: http://www.pluralsight.com/courses/selenium , http://www.pluralsight.com/courses/automated-testing-framework-selenium Best of luck :) More on reddit.com
08:00
Automating Amazon with Selenium and Python: A Comprehensive Tutorial ...
09:28
Flipkart Automation Using Python And Selenium - With Source ...
05:45
How to Use Selenium in Python - YouTube
18:05
Selenium With Python Example For Beginners: Search For Product ...
36:42
Python Selenium Tutorial - Automate Websites and Create Bots - YouTube
YouTube
youtube.com › watch
Retrieving the HTML Source Code of the Web Page using Selenium Python (Selenium Python) - YouTube
Join this channel to get access to perks:https://www.youtube.com/channel/UCH5Lo7qKaAsoN4OXAsNoBbA/joinRefer https://www.qafox.com/ for all my free courses on...
Published: March 3, 2023
GitHub
github.com › seleniumhq › selenium
GitHub - SeleniumHQ/selenium: A browser automation framework and ecosystem. · GitHub
While Selenium is not built with Maven, you can build and install the Selenium pieces for Maven to use locally by deploying to your local maven repository (~/.m2/repository), using: ... Dependencies are defined in the file MODULE.bazel. To update a dependency, modify the version in the MODULE.bazel file and run: ... We follow the PEP8 Style Guide for Python Code (except we use a 120 character line length).
Author: SeleniumHQ
GeeksforGeeks
geeksforgeeks.org › python › selenium-python-basics
Selenium Python Basics - GeeksforGeeks
This code launches Firefox browser and opens Facebook mobile login page using Selenium WebDriver. Python · from selenium import webdriver driver = webdriver.Firefox() driver.get("https://mbasic.facebook.com") You can also use: driver = webdriver.Chrome() # Google Chrome · You can extract the entire HTML source of a loaded web page using driver.page_source.
Published: August 4, 2025
Python Basics
pythonbasics.org › home › selenium › selenium get html source in python
Selenium get HTML source in Python - pythonbasics.org
Do you want to get the HTML source code of a webpage with Python selenium? In this article you will learn how to do that. Selenium is a Python module for browse
Selenium Python
selenium-python.readthedocs.io › installation.html
1. Installation — Selenium Python Bindings 2 documentation
To build Selenium Python from the source code, clone the official repository. It contains the source code for all official Selenium flavors, like Python, Java, Ruby and others. The Python code resides in the /py directory.
freeCodeCamp
forum.freecodecamp.org › curriculum help
Python Selenium - source code reading - Curriculum Help - The freeCodeCamp Forum
January 23, 2021 - Hello! I’ve a problem - I need to find element by class (let’s say class=“hello”) and Selenium Python reads this source code from the top to the bottom - how can I reverse it? How to make Selenium read this code from the bottom () to the top ()? The element with that class I’m looking for is nearly on the bottom of the source code, but Selenium finds the first one from the top…
TutorialsPoint
tutorialspoint.com › accessing-html-source-code-using-python-selenium
Accessing HTML source code using Python Selenium.
Code Implementation. from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/index.htm") # access HTML source code with page_source ...
Starred by 28 users
Forked by 20 users
Languages: Python
Edureka Community
edureka.co › home › community › categories › selenium › how to capture source code of a webpage in...
How to capture source code of a webpage in Selenium using Python | Edureka Community
July 23, 2019 - How to capture source code of a webpage in... ... Chrome Driver has starting But Web socket connection is appearing as null.Tried without Firewall still same issue.Kindly help Oct 15, 2024 · Selenium Webdriver Java - Eclipse java lang NoClassDefFoundError Oct 1, 2024 ... "Error: Unable to initialize main class Commands.Getcommands Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver" how to resolve this?
GeeksforGeeks
geeksforgeeks.org › python › python-page_source-method-in-selenium
Python | page_source method in Selenium - GeeksforGeeks
March 6, 2020 - Return value : It return the page source in string format. Code 1. Python3 · # importing webdriver from selenium from selenium import webdriver # Here Chrome will be used driver = webdriver.Chrome() # URL of the website url = "https://www.geeksforgeeks.org/" # Opening the URL driver.get(url) # Getting current URL source code get_source = driver.page_source # Printing the URL print(get_source) Output : This code will print the source code of the "https://www.geeksforgeeks.org/".
Sauce Labs
saucelabs.com › resources › blog › selenium-with-python-for-automated-testing
Selenium With Python Tutorial & Examples | Sauce Labs
August 24, 2024 - In this article, you'll learn how to use Selenium with Python for automated testing. You will run a variety of tests on a sample website to get a fundamental understanding of automated testing with these tools. ... Selenium is a popular open source framework for automated testing of web applications across multiple browsers, operating systems, and devices.
Selenium Python
selenium-python.readthedocs.io › getting-started.html
2. Getting Started — Selenium Python Bindings 2 documentation
The python which you are running should have the selenium module installed. The selenium.webdriver module provides all the WebDriver implementations. Currently supported WebDriver implementations are Firefox, Chrome, IE and Remote. The Keys class provide keys in the keyboard like RETURN, F1, ALT etc. The By class is used to locate elements within a document. from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By