Created
December 11, 2018 07:37
-
-
Save sotayamashita/1c7530e3983e481da7698f6ffa4343e8 to your computer and use it in GitHub Desktop.
TIL: Start Chrome with WebDriver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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