How to capture source code of a webpage in Selenium using Python?

0 votes
How to capture source code of a webpage in Selenium using Python?
Jul 23, 2019 in Selenium by Hansika
688 views

1 answer to this question.

0 votes

Hi Hansika, you can capture the source code of a webpage using following automation script:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from time import sleep
import io

driver = webdriver.Firefox()
driver.get("https://www.flipkart.com")

elem = driver.find_element_by_xpath("//*")
source_code = elem.get_attribute("innerHTML")

filename = open(flipkart_page_source.html', 'w')
filename.write(source_code)
filename.close()
   
sleep(10)

driver.close()
answered Jul 23, 2019 by Anvi
• 14,090 points

Related Questions In Selenium

0 votes
1 answer

How to get the HTML source of a webpage using Selenium in Java?

There is a method called getPageSource() in ...READ MORE

answered Jan 10, 2019 in Selenium by Sneha
9,478 views
0 votes
2 answers
0 votes
1 answer

How to capture screenshot of a webpage using Selenium Webdriver?

Hi Bindiya, you can use TakesScreenshot interface to capture the ...READ MORE

answered Jul 8, 2019 in Selenium by Abha
• 27,930 points
391 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,090 points
2,374 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,096 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,346 views
0 votes
1 answer
0 votes
1 answer