├── README.md └── going_headless ├── README.md ├── headless_test.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # tutorials 2 | 3 | This repository contains the code for all of the tutorials that have been published on https://duo.com/blog. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
Article Date(s)Tutorial TitleFolder
May 23, 2017Driving Headless Chrome with Python going-headless
17 | -------------------------------------------------------------------------------- /going_headless/README.md: -------------------------------------------------------------------------------- 1 | # Going headless 2 | 3 | This directory contains the code behind the story: Driving Headless Chrome with Python. 4 | -------------------------------------------------------------------------------- /going_headless/headless_test.py: -------------------------------------------------------------------------------- 1 | import os 2 | from selenium import webdriver 3 | from selenium.webdriver.common.keys import Keys 4 | from selenium.webdriver.chrome.options import Options 5 | import time 6 | 7 | chrome_options = Options() 8 | chrome_options.add_argument("--headless") 9 | chrome_options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary' 10 | 11 | driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options) 12 | driver.get("http://www.duo.com") 13 | magnifying_glass = driver.find_element_by_id("js-open-icon") 14 | if magnifying_glass.is_displayed(): 15 | magnifying_glass.click() 16 | else: 17 | menu_button = driver.find_element_by_css_selector(".menu-trigger.local") 18 | menu_button.click() 19 | 20 | search_field = driver.find_element_by_id("site-search") 21 | search_field.clear() 22 | search_field.send_keys("Olabode") 23 | search_field.send_keys(Keys.RETURN) 24 | assert "Looking Back at Android Security in 2016" in driver.page_source 25 | driver.close() 26 | -------------------------------------------------------------------------------- /going_headless/requirements.txt: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------------------- 2 | # 3 | # THIS FILE IS FOR THE APPSEC TEAM'S USE ONLY AND CAN BE IGNORED DURING DEVELOPMENT. 4 | # 5 | #----------------------------------------------------------------------------------- 6 | 7 | # Requirements automatically generated by pigar. 8 | # https://github.com/damnever/pigar 9 | 10 | # going_headless/headless_test.py: 2,3,4 11 | selenium == 3.141.0 12 | --------------------------------------------------------------------------------