def main(argv): os.system('start chrome --remote-debugging-port=9222') options = webdriver.ChromeOptions() # Add option for connecting chromedriver with Chrome options.add_experimental_option("debuggerAddress", "localhost:9222") driver = test_util.create_chrome_webdriver(chrome_options=options, incognito=FLAGS.incognito) driver.get(URL) time.sleep(10) translatePopupVisible = None try: app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') app.top_window() \ .child_window(title="Translate this page?", control_type="Pane") \ .print_control_identifiers() translatePopupVisible = True except ElementNotFoundError as error: translatePopupVisible = False finally: driver.quit() os.system('taskkill /f /im chrome.exe') if translatePopupVisible: print("TRUE") else: print("FALSE")
def download_file_from_url(driver, url, regex, wait, type, message): driver.get(url) time.sleep(wait) try: app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') app.top_window() \ .child_window(title_re=regex, control_type=type) print message except ElementNotFoundError as error: print error
def main(argv): exclude_switches = ["disable-background-networking"] chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("excludeSwitches", exclude_switches) driver = test_util.create_chrome_webdriver(chrome_options=chrome_options) try: app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') window = app.top_window() # Wait for Chrome to download SafeBrowsing lists in the background. # There's no trigger to force this operation or synchronize on it, but quick # experiments have shown 3-4 minutes in most cases, so 5 should be plenty. time.sleep(60 * 5) # Verify Policy status legend in chrome://policy page policy_url = "chrome://policy" driver.get(policy_url) driver.find_element_by_id('reload-policies').click deviceId = driver.find_element_by_class_name( 'machine-enrollment-device-id').text visit(window, UnsafePageLink) visit(window, UnsafeDownloadLink) print('\nDeviceId:' + deviceId.strip()) except Exception as error: print(error) finally: driver.quit()
def main(argv): exclude_switches = ["disable-background-networking"] options = webdriver.ChromeOptions() options.add_argument("--force-renderer-accessibility") options.add_experimental_option("excludeSwitches", exclude_switches) os.environ["CHROME_LOG_FILE"] = r"c:\temp\chrome_log.txt" driver = test_util.create_chrome_webdriver(chrome_options=options) app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') window = app.top_window() # Wait for browser enrolling time.sleep(15) # Click reload policy to pull cloud policies from the server side policy_url = "chrome://policy" driver.get(policy_url) driver.find_element_by_id('reload-policies').click download_file_from_url(driver, encrypted_file_url, encrypted_block_text, 30, "Button", "Encrypted blocked") download_file_from_url(driver, large_file_url, large_block_text, 30, "Button", "Large file blocked") download_file_from_url(driver, unknown_malware_url, unknown_malware_block_text, 2, "Text", "Unknown malware scanning") driver.quit()
def main(argv): exclude_switches = ["disable-background-networking"] chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("excludeSwitches", exclude_switches) driver = test_util.create_chrome_webdriver(chrome_options=chrome_options) app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') window = app.top_window() # Wait for Chrome to download SafeBrowsing lists in the background. # There's no trigger to force this operation or synchronize on it, but quick # experiments have shown 3-4 minutes in most cases, so 5 should be plenty. time.sleep(60 * 5) print "Visiting unsafe page: %s" % UnsafePageLink visit(window, UnsafePageLink) unsafe_page = False for desc in app.top_window().descendants(): if desc.window_text(): print "unsafe_page.item: %s" % desc.window_text() if UnsafePageLinkTabText in desc.window_text(): unsafe_page = True break print "Downloading unsafe file: %s" % UnsafeDownloadLink visit(window, UnsafeDownloadLink) unsafe_download = False for desc in app.top_window().descendants(): if desc.window_text(): print "unsafe_download.item: %s" % desc.window_text() if re.search(UnsafeDownloadTextRe, desc.window_text()): unsafe_download = True break print "RESULTS.unsafe_page: %s" % unsafe_page print "RESULTS.unsafe_download: %s" % unsafe_download driver.quit()
def main(argv): chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--force-renderer-accessibility") #Always set useAutomationExtension as false to avoid failing launch Chrome #https://bugs.chromium.org/p/chromedriver/issues/detail?id=2930 chrome_options.add_experimental_option("useAutomationExtension", False) driver = test_util.create_chrome_webdriver(chrome_options=chrome_options) app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') driver.get(FLAGS.url) time.sleep(5) driver.find_element_by_xpath("//div[@aria-label='Add to Chrome']").click() try: app.top_window() \ .child_window(title_re='.*Your admin has blocked', control_type="TitleBar") \ .print_control_identifiers() except ElementNotFoundError as error: print "Not blocked" finally: driver.quit()
def main(argv): driver = test_util.create_chrome_webdriver(incognito=FLAGS.incognito) driver.get(URL) time.sleep(10) app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') translatePopupVisible = False for desc in app.top_window().descendants(): if 'Translate this page?' in desc.window_text(): translatePopupVisible = True break if translatePopupVisible: print "TRUE" else: print "FALSE" driver.quit()
def main(argv): os.system('start chrome --remote-debugging-port=9222') options = webdriver.ChromeOptions() options.add_argument("--force-renderer-accessibility") options.add_experimental_option("debuggerAddress", "localhost:9222") driver = test_util.create_chrome_webdriver(chrome_options=options) app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') # Wait for browser enrolling time.sleep(15) # Click reload policy to pull cloud policies from the server side policy_url = "chrome://policy" driver.get(policy_url) driver.find_element_by_id('reload-policies').click # paste content from clipboard to the form driver.get(paste_url) form = driver.find_element_by_name('sensitive_data_scan') pyperclip.copy(FLAGS.text) form.send_keys(Keys.CONTROL, "v") time.sleep(20) try: # Print the UI elements which contain text for desc in app.top_window().descendants(): print(desc.window_text()) # Check if the paste is completed in form if form.get_attribute('value') == FLAGS.text: print("Paste is done") else: print("Paste is blocked") except: print("Error occurs") finally: driver.quit() os.system('taskkill /f /im chrome.exe')