email – SAVE THE HTML PAGE USING PYTHON

[ad_1]

from selenium import webdriver
from selenium.webdriver.common.by import By
import os
#import time

login_url = “https://stureg.ioqmexam.in/Login”
dob = “01/01/2009” # Use a specific date for testing

output_directory = “html_pages”
image_directory = “images”
os.makedirs(output_directory, exist_ok=True)
os.makedirs(image_directory, exist_ok=True)

driver = webdriver.Firefox()

try:
# Navigate to the login page
driver.get(login_url)

# Locate elements
username_field = driver.find_element(By.NAME, "RegNo")
password_field = driver.find_element(By.NAME, "DOB")
login_button = driver.find_element(By.XPATH, '//*[@id="counts"]/div/div/div[2]/div/div/div/div/div/div/div/form/div[3]/div[2]/button')

# Fill in credentials
username_field.clear()
username_field.send_keys("YourRegNo")  # Replace with a valid registration number
password_field.clear()
password_field.send_keys(dob)

# Click login button
login_button.click()

# Introduce a delay to allow the page to load (you can adjust the sleep duration as needed)
#time.sleep(5)

# Save the page source as an HTML file
page_source = driver.page_source
html_file_path = os.path.join(output_directory, "test_page.html")
with open(html_file_path, "w", encoding="utf-8") as html_file:
    html_file.write(page_source)

# Capture and save the entire browser window as an image
browser_screenshot_path = os.path.join(image_directory, "test_browser_screenshot.png")
driver.save_screenshot(browser_screenshot_path)

print(f"HTML file saved at: {html_file_path}")
print(f"Browser screenshot saved at: {browser_screenshot_path}")

except Exception as e:
print(f”An error occurred: {e}”)

finally:
# Close the Firefox WebDriver
driver.quit()

[ad_2]

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top