Skip to content

Instantly share code, notes, and snippets.

@sotayamashita
Created December 11, 2018 07:37
Show Gist options
  • Save sotayamashita/1c7530e3983e481da7698f6ffa4343e8 to your computer and use it in GitHub Desktop.
Save sotayamashita/1c7530e3983e481da7698f6ffa4343e8 to your computer and use it in GitHub Desktop.
TIL: Start Chrome with WebDriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
options = Options()
options.add_argument('--headless')
# Other options are here. http://chromedriver.chromium.org/capabilities
driver = webdriver.Chrome(chrome_options=options)
driver.get("")
try:
element = driver.find_element_by_css_selector("")
print(element.rect)
driver.execute_script("arguments[0].scrollIntoView(true);", element)
except:
driver.close()
if os.path.exists("sample.png"):
os.remove("sample.png")
driver.save_screenshot('sample.png')
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment