Take a Screenshot of a web page and “Click” buttons in a web page

Here we will take a screen shot of the Ocean Viewer page. Since it has a welcome alert that we do not want included in the screenshot we closed the welcome alert before taking the screen shot.

Ocean Viewer Screen Shot

 

#Import Selenium Webdriver
from selenium import webdriver

#open Fire fox
driver = webdriver.Firefox()

# Resize the window to the desired screen width/height
driver.set_window_size(1300, 800)

#Open URL
driver.get('http://oceanviewer.org/atlantic-canada/temperature/')

# Close welcome screen
#To find element id right click on button and hit select inspect element 
#The name will be in a bubble above the text. 
#In our case the element id is close welcome screen 
driver.find_element_by_id("close_welcome").click()

#save screenshot
driver.save_screenshot('screenshot1.png')

#close window
driver.quit()

Advertisements