Examples
Make sure you have the selenium
package installed in your environment.
Basic Example
import os
from selenium import webdriver
ABSTRA_ENVIRONMENT = os.getenv('ABSTRA_ENVIRONMENT')
ABSTRA_SELENIUM_URL = os.getenv('ABSTRA_SELENIUM_URL')
if ABSTRA_ENVIRONMENT=='production':
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
driver = webdriver.Remote(command_executor=ABSTRA_SELENIUM_URL, options=options)
else:
driver = webdriver.Chrome()
driver.get("https://abstra.io")
driver.save_screenshot("/tmp/screenshot.png")
driver.quit()
Downloading Files
info
Talk to us if you need to download files from the Selenium environment. It's disabled by default for security reasons.
import os
from selenium import webdriver
ABSTRA_ENVIRONMENT = os.getenv('ABSTRA_ENVIRONMENT')
ABSTRA_SELENIUM_URL = os.getenv('ABSTRA_SELENIUM_URL')
def get_driver():
if ABSTRA_ENVIRONMENT=='production' and ABSTRA_SELENIUM_URL:
def get_default_chrome_options():
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
options.set_capability("se:downloadsEnabled", True)
return options
options = get_default_chrome_options()
return webdriver.Remote(command_executor=ABSTRA_SELENIUM_URL, options=options)
else:
return webdriver.Chrome()
driver = get_driver()
## Download last file
if ABSTRA_ENVIRONMENT=='production':
files = driver.get_downloadable_files()
print(f"Downloadable files: {files}")
driver.download_file(files[0], "downloads/")
print("Script completed, quitting driver.")
driver.quit()