-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium_test.py
More file actions
42 lines (34 loc) · 1.46 KB
/
selenium_test.py
File metadata and controls
42 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from bs4 import BeautifulSoup
from selenium.common.exceptions import NoSuchElementException
def create_firefox_browser():
"""
Creates a Firefox Selenium instance and logs in using the credentials file passed in (or asks for it).
:param credentials_file: Location of credentials file
:return: Firefox browser instance (headless)
"""
# set headless mode
ff_options = FirefoxOptions()
ff_options.add_argument("--headless")
ff_options.set_preference("javascript.enabled", True)
# create the browser instance
browser = webdriver.Firefox(ff_options)
#** Sample code to test the browser **#
"""
# basic authentication
browser.get('https://www.commcarehq.org/accounts/login/')
# find the login form fields (username, password, and submit button)
username_field = browser.find_element_by_id('id_auth-username')
password_field = browser.find_element_by_id('id_auth-password')
submit_button = browser.find_element_by_css_selector('.btn.btn-primary.btn-lg')
# fill out the username and password
username_field.send_keys(username)
password_field.send_keys(password)
# submit the login form
submit_button.click()
# confirm we're authenticated
if 'My Projects' not in browser.title:
raise ValueError('Authentication failed. Please check credentials.')
"""
return browser