Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.7k points)

How can I get the HTML source in a variable using the Selenium module with Python?

I wanted to do something like this:

from selenium import webdriver
= webdriver.Firefox()
browser.get(raw_input("Enter URL: "))
if "whatever" in html_source:
    # Do something
    # Do something else

How can I do this? I don't know how to access the HTML source.

1 Answer

0 votes
by (62.9k points)

By using the page source you will get the whole HTML code.

So first decide the block of code or tag in which you require to retrieve the data or to click the element..

options = driver.find_elements_by_name_("XXX") 

for option in options: 

if option.text == "XXXXXX": 


You can find the elements by name, XPath, id, link and CSS path. 

Hope this helps!

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories