from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from time import sleep from selenium.common.exceptions import NoSuchElementException # from PIL import Image URL = 'https://sc1uxpremn81:8000/en-US/app/wh_netacea_blocking/byo_decoder_wip' URL2 = ( 'https://sc1uxpremn81:8000/en-US/app/wh_netacea_blocking/' 'blocking_visibility?form.time_tok.earliest=%40d&form.time_tok.latest=now' ) options = webdriver.ChromeOptions() options.headless = True driver = webdriver.Chrome(options=options) driver.get(URL2) driver.implicitly_wait(10) driver.maximize_window() action = ActionChains(driver) username = driver.find_element_by_xpath('//*[@id="username"]') password = driver.find_element_by_xpath('//*[@id="password"]') username.send_keys('admin') password.send_keys('fWgbz6AU') driver.find_element_by_xpath( '/html/body/div[2]/div/div/div[1]/form/fieldset/input[1]' ).click() def setWidth(var, adj=0): script = "return document.body.parentNode.scroll" + (var) return driver.execute_script(script) + adj driver.set_window_size(setWidth('Width', 1000), setWidth('Height', 10000)) sleep(2) try: driver.find_element_by_xpath( '/html/body/div[2]/div/div[3]/div[1]/a' ).click() except NoSuchElementException: pass try: element = driver.find_element_by_class_name('dashboard-menu') driver.execute_script("arguments[0].style.visibility = 'hidden';", element) except NoSuchElementException: pass try: action.move_to_element( driver.find_element_by_class_name('dashboard-title') ).perform() sleep(1) except NoSuchElementException: pass driver.find_element_by_xpath('/html/body/div[2]').screenshot( 'web_screenshot.png' ) driver.quit()