0 votes
1 view
in AWS by (19.8k 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
browser
= webdriver.Firefox()
browser.get(raw_input("Enter URL: "))
if "whatever" in html_source:
    # Do something
else:
    # Do something else

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

1 Answer

0 votes
by (63.4k 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": 

print(option.text) 

option.click()

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

Hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...