def __init__(self, driver_type='chrome', capabilities=None, pasta_user=None, wait_time=DEFAULT_WAIT_TIME, remote_driver='', existing_driver=None, **kwargs): """Class constructor.""" if driver_type == 'saucelabs' and pasta_user is None: raise TypeError('A Sauce Labs user is required for remote testing') self.pasta = pasta_user self.remote_driver = remote_driver if existing_driver: self.driver = existing_driver else: driver = driver_type if not pasta_user else 'saucelabs' self.driver = self.run_on(driver_type=driver, pasta_user=self.pasta, capabilities=capabilities) self.driver.implicitly_wait(wait_time) self.wait = WebDriverWait(self.driver, wait_time) self.wait_time = wait_time self.page = Page(self.driver, self.wait_time) # super(Helper, self).__init__(**kwargs) super(Helper, self).__init__()
def __init__(self, driver_type='chrome', capabilities=None, pasta_user=None, wait_time=DEFAULT_WAIT_TIME, opera_driver='', existing_driver=None, **kwargs): """Class constructor.""" if driver_type == 'saucelabs' and pasta_user is None: raise TypeError('A Sauce Labs user is required for remote testing') self.pasta = pasta_user self.opera_driver = opera_driver if existing_driver: self.driver = existing_driver else: driver = driver_type if not pasta_user else 'saucelabs' self.driver = self.run_on(driver_type=driver, pasta_user=self.pasta, capabilities=capabilities) self.driver.implicitly_wait(wait_time) self.wait = WebDriverWait(self.driver, wait_time) self.wait_time = wait_time self.page = Page(self.driver, self.wait_time) super(Helper, self).__init__(**kwargs)
def setUp(self): """Pretest settings.""" option_set = options.Options() option_set.add_argument("disable-infobars") option_set.add_argument('disable-geolocation') option_set.add_argument('headless') option_set.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } } ) self.driver = webdriver.Chrome(chrome_options=option_set) self.driver.implicitly_wait(0) self.wait = SeleniumWait(self.driver)
def delete_reading(self, driver, title, description, periods, readings, status): """Delete a reading assignment.""" print('Delete Reading: %s' % title) wait = WebDriverWait(driver, Assignment.WAIT_TIME * 4) due_date = '' for period in periods: _, due_date = periods[period] break url = driver.current_url.split('/') date = due_date.split('/') temp = [] temp.append(date[2]) temp.append(date[0]) temp.append(date[1]) date = '-'.join(temp) url.append('month') url.append(date) url = '/'.join(url) driver.get(url) page = Page(driver, Assignment.WAIT_TIME) page.wait_for_page_load() wait.until( expect.presence_of_element_located( (By.XPATH, '//div[div[label[text()="%s"]]]' % title) ) ).click() time.sleep(0.3) try: modal = driver.find_element( By.XPATH, '//div[@class="modal-footer"]/a[2]' ) Assignment.scroll_to(driver, modal) modal.click() except Exception: pass page.wait_for_page_load() time.sleep(3) wait.until( expect.visibility_of_element_located( (By.XPATH, '//button[contains(@class, "delete-link")]') ) ).click() wait.until( expect.visibility_of_element_located( (By.XPATH, '//div[@class="controls"]/button[text()="Yes"]') ) ).click() page.wait_for_page_load()
def delete_reading(self, driver, title, description, periods, readings, status): """Delete a reading assignment.""" # raise NotImplementedError(inspect.currentframe().f_code.co_name) wait = WebDriverWait(driver, Assignment.WAIT_TIME * 4) wait.until( expect.visibility_of_element_located( (By.XPATH, '//ul/a[contains(@class,"navbar-brand")]') ) ).click() due_date = '' for period in periods: _, due_date = periods[period] break url = driver.current_url.split('/') date = due_date.split('/') temp = [] temp.append(date[2]) temp.append(date[0]) temp.append(date[1]) date = '-'.join(temp) url[-2] = date url = '/'.join(url) driver.get(url) page = Page(driver, Assignment.WAIT_TIME) page.wait_for_page_load() wait.until( expect.presence_of_element_located( (By.XPATH, '//a[label[text()="%s"]]' % title) ) ).click() time.sleep(0.3) try: modal = driver.find_element(By.CLASS_NAME, '-edit-assignment') Assignment.scroll_to(driver, modal) modal.click() except: pass page.wait_for_page_load() wait.until( expect.presence_of_element_located( (By.CLASS_NAME, 'delete-link') ) ).click() wait.until( expect.presence_of_element_located( (By.XPATH, '//div[@class="controls"]/button[text()="Yes"]') ) ).click() page.wait_for_page_load()
class Helper(object): """Primary parent control class.""" CONDENSED_WIDTH = 767 # pixels wide DEFAULT_WAIT_TIME = 15 # seconds CAPABILITIES = { 'android': DesiredCapabilities.ANDROID, 'chrome': DesiredCapabilities.CHROME, 'firefox': DesiredCapabilities.FIREFOX, 'htmlunit': DesiredCapabilities.HTMLUNIT, 'htmlunitwithjs': DesiredCapabilities.HTMLUNITWITHJS, 'internetexplorer': DesiredCapabilities.INTERNETEXPLORER, 'ipad': DesiredCapabilities.IPAD, 'iphone': DesiredCapabilities.IPHONE, 'microsoftedge': DesiredCapabilities.EDGE, 'opera': DesiredCapabilities.OPERA, 'phantomjs': DesiredCapabilities.PHANTOMJS, 'safari': DesiredCapabilities.SAFARI, } def __init__(self, driver_type='chrome', capabilities=None, pasta_user=None, wait_time=DEFAULT_WAIT_TIME, opera_driver='', existing_driver=None, **kwargs): """Class constructor.""" if driver_type == 'saucelabs' and pasta_user is None: raise TypeError('A Sauce Labs user is required for remote testing') self.pasta = pasta_user self.opera_driver = opera_driver if existing_driver: self.driver = existing_driver else: driver = driver_type if not pasta_user else 'saucelabs' self.driver = self.run_on(driver_type=driver, pasta_user=self.pasta, capabilities=capabilities) self.driver.implicitly_wait(wait_time) self.wait = WebDriverWait(self.driver, wait_time) self.wait_time = wait_time self.page = Page(self.driver, self.wait_time) super(Helper, self).__init__(**kwargs) def __enter__(self): """Entry point.""" return self def __del__(self): """Class destructor.""" self.delete() def __exit__(self, exc_type, exc_val, exc_tb): """Class exitor.""" self.delete() def delete(self): """Webdriver destructor.""" self.wait = None try: self.driver.quit() except: pass @classmethod def default_capabilities(cls, browser='chrome'): """Return the default browser capabilities.""" browser = browser.lower() browser = ''.join(browser.split()) return Helper.CAPABILITIES[browser].copy() def run_on(self, driver_type, pasta_user=None, capabilities={}): """Webdriver activation. driver_type (string): web browser type pasta_user (PastaSauce): optional API access for saucelabs capabilities (dict): browser settings; copy object to avoid overwrite Defaults: DesiredCapabilities.ANDROID.copy() DesiredCapabilities.CHROME.copy() DesiredCapabilities.EDGE.copy() DesiredCapabilities.FIREFOX.copy() DesiredCapabilities.HTMLUNIT.copy() DesiredCapabilities.HTMLUNITWITHJS.copy() DesiredCapabilities.INTERNETEXPLORER.copy() DesiredCapabilities.IPAD.copy() DesiredCapabilities.IPHONE.copy() DesiredCapabilities.ORERA.copy() DesiredCapabilities.PHANTOMJS.copy() DesiredCapabilities.SAFARI.copy() Keys: platform browserName version javascriptEnabled wait (int): standard time, in seconds, to wait for Selenium commands opera_driver (string): Chromium location """ if pasta_user: driver = 'saucelabs' elif driver_type: driver = driver_type else: driver = 'chrome' try: return { 'firefox': lambda: webdriver.Firefox(), 'chrome': lambda: webdriver.Chrome(), 'ie': lambda: webdriver.Ie(), 'opera': lambda: self.start_opera(self.opera_driver), 'phantomjs': lambda: webdriver.PhantomJS(), # 'safari': lambda: webdriver.Safari(), 'saucelabs': lambda: webdriver.Remote( command_executor=( 'http://%s:%[email protected]:80/wd/hub' % (pasta_user.get_user(), pasta_user.get_access_key())), desired_capabilities=capabilities ), }[driver]() except WebDriverException as err: raise FileNotFoundError(err) except Exception as err: raise err def start_opera(self, location): """Opera initiator.""" webdriver_service = service.Service(location) webdriver_service.start() return webdriver.Remote( webdriver_service.service_url, DesiredCapabilities.OPERA.copy() ) def change_wait_time(self, new_wait): """Change the max action wait time.""" if new_wait <= 0: raise ValueError('Wait time must be 1 or higher.') self.driver.implicitly_wait(new_wait) self.wait = WebDriverWait(self.driver, new_wait) self.wait_time = new_wait def date_string(self, day_delta=0, str_format='%m/%d/%Y'): """System date format for Tutor.""" return (datetime.date.today() + datetime.timedelta(days=day_delta)). \ strftime(str_format) def get(self, url): """Return the current URL.""" self.driver.get(url) self.page.wait_for_page_load() def get_window_size(self, dimension=None): """Return the current window dimensions.""" get_size = self.driver.get_window_size() if dimension is None: return get_size if dimension not in get_size: raise IndexError('Unknown dimension: %s' % dimension) return get_size[dimension] def set_window_size(self, width=0, height=0, maximize=False): """Attempt to change the browser window size.""" if maximize: self.driver.maximize_window() elif width >= 1 and height >= 1: self.driver.set_window_size(width, height) sleep(1.0) return self.get_window_size() def set_window_position(self, x_=0, y_=0): """Move the browser window anchor.""" if x_ >= 0 and y_ >= 0: self.driver.set_window_position(x_, y_) sleep(1.0) def sleep(self, seconds=1): """Stop execution for the specified time in seconds.""" sleep(seconds) def find(self, by, value): """Find element.""" return self.driver.find_element(by=by, value=value) def find_all(self, by, value): """Find elements.""" return self.driver.find_elements(by=by, value=value)
class TestStaxingSeleniumWait(unittest.TestCase): """Staxing case tests for the page loading wait.""" def setUp(self): """Pretest settings.""" option_set = options.Options() option_set.add_argument("disable-infobars") option_set.add_argument('disable-geolocation') option_set.add_argument('headless') option_set.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } } ) self.driver = webdriver.Chrome(chrome_options=option_set) self.driver.implicitly_wait(0) self.wait = SeleniumWait(self.driver) def tearDown(self): """Test destructor.""" try: self.driver.__del__() self.wait.__del__() except Exception: pass def test_wait_for_page_load(self): """Verify successful waits.""" self.driver.implicitly_wait(0) self.driver.get('https://openstax.org') # immediate element search should fail # with self.assertRaises(NoSuchElementException): # self.driver.find_element_by_id('main') self.driver.get('https://openstax.org') # yield execution until the page is stale and content is loaded self.wait.wait_for_page_load() self.driver.find_element_by_id('main') def test_wait_for_loading_staleness(self): """Test for loading staleness.""" self.driver.implicitly_wait(15) self.driver.get('http://www.ikea.com/us/en/') assert(self.wait.wait_for_loading_staleness(_id='SlideIndiacator')), \ 'transition not stale' pass def test_is_pseduo_valid(self): """Validate the pseudo selectors.""" self.driver.get( 'https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements' ) pseudos = self.driver.find_elements_by_css_selector( '#Index_of_pseudo-elements + ul > li code' ) for i, _ in enumerate(pseudos): pseudos[i] = pseudos[i].get_attribute('innerHTML') for pseudo in pseudos: assert(self.wait.is_valid_pseudo(pseudo)), \ '%s is not a valid pseudo element' % pseudo
class Helper(object): """Primary parent control class.""" CONDENSED_WIDTH = 767 # pixels wide DEFAULT_WAIT_TIME = 15 # seconds CAPABILITIES = { 'android': DesiredCapabilities.ANDROID, 'chrome': DesiredCapabilities.CHROME, 'firefox': DesiredCapabilities.FIREFOX, 'headlesschrome': DesiredCapabilities.CHROME, 'htmlunit': DesiredCapabilities.HTMLUNIT, 'htmlunitwithjs': DesiredCapabilities.HTMLUNITWITHJS, 'internetexplorer': DesiredCapabilities.INTERNETEXPLORER, 'ipad': DesiredCapabilities.IPAD, 'iphone': DesiredCapabilities.IPHONE, 'microsoftedge': DesiredCapabilities.EDGE, 'opera': DesiredCapabilities.OPERA, 'safari': DesiredCapabilities.SAFARI, } def __init__(self, driver_type='chrome', capabilities=None, pasta_user=None, wait_time=DEFAULT_WAIT_TIME, remote_driver='', existing_driver=None, **kwargs): """Class constructor.""" if driver_type == 'saucelabs' and pasta_user is None: raise TypeError('A Sauce Labs user is required for remote testing') self.pasta = pasta_user self.remote_driver = remote_driver if existing_driver: self.driver = existing_driver else: driver = driver_type if not pasta_user else 'saucelabs' self.driver = self.run_on(driver_type=driver, pasta_user=self.pasta, capabilities=capabilities) self.driver.implicitly_wait(wait_time) self.wait = WebDriverWait(self.driver, wait_time) self.wait_time = wait_time self.page = Page(self.driver, self.wait_time) # super(Helper, self).__init__(**kwargs) super(Helper, self).__init__() def __enter__(self): """Entry point.""" return self def __del__(self): """Class destructor.""" self.delete() def __exit__(self, exc_type, exc_val, exc_tb): """Class exitor.""" self.delete() def delete(self): """Webdriver destructor.""" self.wait = None try: self.driver.quit() except: pass @classmethod def default_capabilities(cls, browser='chrome'): """Return the default browser capabilities.""" browser = browser.lower() browser = ''.join(browser.split()) return Helper.CAPABILITIES[browser].copy() def run_on(self, driver_type, pasta_user=None, capabilities={}): """Webdriver activation. driver_type (string): web browser type pasta_user (PastaSauce): optional API access for saucelabs capabilities (dict): browser settings; copy object to avoid overwrite Defaults: DesiredCapabilities.ANDROID.copy() DesiredCapabilities.CHROME.copy() DesiredCapabilities.EDGE.copy() DesiredCapabilities.FIREFOX.copy() DesiredCapabilities.HTMLUNIT.copy() DesiredCapabilities.HTMLUNITWITHJS.copy() DesiredCapabilities.INTERNETEXPLORER.copy() DesiredCapabilities.IPAD.copy() DesiredCapabilities.IPHONE.copy() DesiredCapabilities.ORERA.copy() DesiredCapabilities.SAFARI.copy() Keys: platform browserName version javascriptEnabled wait (int): standard time, in seconds, to wait for Selenium commands opera_driver (string): Chromium location """ print('Driver type input: %s' % driver_type) if pasta_user: driver = 'saucelabs' print('Driver type: %s' % driver) elif driver_type and driver_type is not 'chrome': driver = driver_type print('Driver type: %s' % driver) else: option_set = options.Options() option_set.add_argument("disable-infobars") option_set.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) driver = 'chrome' print('Driver type: %s' % driver) try: return { 'firefox': lambda: webdriver.Firefox(), 'chrome': lambda: webdriver.Chrome(chrome_options=option_set), 'headlesschrome': lambda: self.start_headless(), 'ie': lambda: webdriver.Ie(), 'opera': lambda: self.start_opera(self.opera_driver), 'safari': lambda: webdriver.Safari(), 'saucelabs': lambda: webdriver.Remote(command_executor=( 'http://%s:%[email protected]:80/wd/hub' % (pasta_user.get_user(), pasta_user.get_access_key())), desired_capabilities=capabilities), }[driver]() except WebDriverException as err: raise FileNotFoundError(err) except Exception as err: raise err def start_headless(self): """Headless Chrome initiator.""" print('Start headless browser') option_set = options.Options() option_set.add_arguments("test-type") option_set.add_arguments("start-maximized") option_set.add_arguments("--js-flags=--expose-gc") option_set.add_arguments("--enable-precise-memory-info") option_set.add_argument('headless') option_set.add_argument('disable-notifications') option_set.add_argument('disable-gpu') option_set.add_argument('disable-infobars') option_set.add_arguments("--disable-default-apps") option_set.add_arguments("test-type=browser") option_set.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) option_set.binary_location = os.getenv( 'CHROME_CANARY', '/Applications/Google Chrome Canary.app' + '/Contents/MacOS/Google Chrome Canary') webdriver_service = service.Service( os.getenv('CHROMEDRIVER', '/Applications/chromedriver')) webdriver_service.start() print('Service started; returning Remote webdriver') return webdriver.Remote(webdriver_service.service_url, option_set.to_capabilities()) def start_opera(self, location): """Opera initiator.""" webdriver_service = service.Service(location) webdriver_service.start() return webdriver.Remote(webdriver_service.service_url, DesiredCapabilities.OPERA.copy()) def change_wait_time(self, new_wait): """Change the max action wait time.""" if new_wait <= 0: raise ValueError('Wait time must be 1 or higher.') self.driver.implicitly_wait(new_wait) self.wait = WebDriverWait(self.driver, new_wait) self.wait_time = new_wait def date_string(self, day_delta=0, str_format='%m/%d/%Y'): """System date format for Tutor.""" return (datetime.date.today() + datetime.timedelta(days=day_delta)). \ strftime(str_format) def get(self, url): """Return the current URL.""" self.driver.get(url) self.page.wait_for_page_load() def get_window_size(self, dimension=None): """Return the current window dimensions.""" get_size = self.driver.get_window_size() if dimension is None: return get_size if dimension not in get_size: raise IndexError('Unknown dimension: %s' % dimension) return get_size[dimension] def set_window_size(self, width=0, height=0, maximize=False): """Attempt to change the browser window size.""" if maximize: self.driver.maximize_window() elif width >= 1 and height >= 1: self.driver.set_window_size(width, height) sleep(1.0) return self.get_window_size() def set_window_position(self, x_=0, y_=0): """Move the browser window anchor.""" if x_ >= 0 and y_ >= 0: self.driver.set_window_position(x_, y_) sleep(1.0) def sleep(self, seconds=1): """Stop execution for the specified time in seconds.""" sleep(seconds) def find(self, by, value): """Find element.""" return self.driver.find_element(by=by, value=value) def find_all(self, by, value): """Find elements.""" return self.driver.find_elements(by=by, value=value)
class Helper(object): """Primary parent control class.""" CONDENSED_WIDTH = 767 # pixels wide DEFAULT_WAIT_TIME = 15 # seconds CAPABILITIES = { 'android': DesiredCapabilities.ANDROID, 'chrome': DesiredCapabilities.CHROME, 'firefox': DesiredCapabilities.FIREFOX, 'headlesschrome': DesiredCapabilities.CHROME, 'htmlunit': DesiredCapabilities.HTMLUNIT, 'htmlunitwithjs': DesiredCapabilities.HTMLUNITWITHJS, 'internetexplorer': DesiredCapabilities.INTERNETEXPLORER, 'ipad': DesiredCapabilities.IPAD, 'iphone': DesiredCapabilities.IPHONE, 'microsoftedge': DesiredCapabilities.EDGE, 'opera': DesiredCapabilities.OPERA, 'safari': DesiredCapabilities.SAFARI, } def __init__(self, driver_type='chrome', capabilities=None, pasta_user=None, wait_time=DEFAULT_WAIT_TIME, remote_driver='', existing_driver=None, **kwargs): """Class constructor.""" if driver_type == 'saucelabs' and pasta_user is None: raise TypeError('A Sauce Labs user is required for remote testing') self.pasta = pasta_user self.remote_driver = remote_driver self.driver_type = driver_type.lower() if existing_driver: self.driver = existing_driver else: driver = driver_type if not pasta_user else 'saucelabs' self.driver = self.run_on(driver_type=driver, pasta_user=self.pasta, capabilities=capabilities) self.driver.implicitly_wait(wait_time) self.wait = WebDriverWait(self.driver, wait_time) self.wait_time = wait_time self.page = Page(self.driver, self.wait_time) super(Helper, self).__init__() def __enter__(self): """Entry point.""" return self def __del__(self): """Class destructor.""" self.delete() def __exit__(self, exc_type, exc_val, exc_tb): """Class exitor.""" self.delete() def delete(self): """Webdriver destructor.""" self.wait = None try: self.driver.quit() except Exception: pass @classmethod def default_capabilities(cls, browser='chrome'): """Return the default browser capabilities.""" browser = browser.lower() browser = ''.join(browser.split()) return Helper.CAPABILITIES[browser].copy() def run_on(self, driver_type, pasta_user=None, capabilities={}): """Webdriver activation. driver_type (string): web browser type pasta_user (PastaSauce): optional API access for saucelabs capabilities (dict): browser settings; copy object to avoid overwrite Defaults: DesiredCapabilities.ANDROID.copy() DesiredCapabilities.CHROME.copy() DesiredCapabilities.EDGE.copy() DesiredCapabilities.FIREFOX.copy() DesiredCapabilities.HTMLUNIT.copy() DesiredCapabilities.HTMLUNITWITHJS.copy() DesiredCapabilities.INTERNETEXPLORER.copy() DesiredCapabilities.IPAD.copy() DesiredCapabilities.IPHONE.copy() DesiredCapabilities.ORERA.copy() DesiredCapabilities.SAFARI.copy() Keys: platform browserName version javascriptEnabled wait (int): standard time, in seconds, to wait for Selenium commands opera_driver (string): Chromium location """ if pasta_user: driver = 'saucelabs' elif driver_type and 'chrome' not in driver_type: driver = driver_type else: option_set = options.Options() option_set.add_argument('disable-infobars') option_set.add_argument('disable-geolocation') option_set.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) if 'headless' in driver_type: option_set.add_argument('headless') driver = 'headlesschrome' else: driver = 'chrome' try: return { 'firefox': lambda: webdriver.Firefox(), 'chrome': lambda: webdriver.Chrome(chrome_options=option_set), 'headlesschrome': lambda: webdriver.Chrome(chrome_options=option_set), 'ie': lambda: webdriver.Ie(), 'opera': lambda: self.start_opera(self.opera_driver), 'safari': lambda: webdriver.Safari(), 'saucelabs': lambda: webdriver.Remote(command_executor=( 'http://%s:%[email protected]:80/wd/hub' % (pasta_user.get_user(), pasta_user.get_access_key())), desired_capabilities=capabilities), }[driver]() except WebDriverException as err: raise FileNotFoundError(err) except Exception as err: raise err def start_opera(self, location): """Opera initiator.""" webdriver_service = service.Service(location) webdriver_service.start() return webdriver.Remote(webdriver_service.service_url, DesiredCapabilities.OPERA.copy()) def change_wait_time(self, new_wait): """Change the max action wait time.""" if new_wait <= 0: raise ValueError('Wait time must be greater than zero (0).') self.driver.implicitly_wait(new_wait) self.wait = WebDriverWait(self.driver, new_wait) self.wait_time = new_wait def date_string(self, day_delta=0, str_format='%m/%d/%Y'): """System date format pass-through.""" return Assignment().to_date_string(day_delta, str_format) def get(self, url): """Return the current URL.""" self.driver.get(url) self.page.wait_for_page_load() def get_window_size(self, dimension=None): """Return the current window dimensions.""" get_size = self.driver.get_window_size() if not dimension: return get_size if dimension not in get_size: raise IndexError('Unknown dimension: %s' % dimension) return get_size[dimension] def set_window_size(self, width=0, height=0, maximize=False): """Attempt to change the browser window size.""" if maximize: self.driver.maximize_window() elif width >= 1 and height >= 1: self.driver.set_window_size(width, height) sleep(1.0) return self.get_window_size() def set_window_position(self, x_=0, y_=0): """Move the browser window anchor.""" if x_ >= 0 and y_ >= 0: self.driver.set_window_position(x_, y_) sleep(1.0) def sleep(self, seconds=1.0): """Stop execution for the specified time in seconds.""" sleep(seconds) def find(self, by, value): """Find element.""" return self.driver.find_element(by=by, value=value) def find_all(self, by, value): """Find elements.""" return self.driver.find_elements(by=by, value=value) def scroll_to(self, target): """Scroll the browser window to bring the target into view.""" Assignment.scroll_to(self.driver, target) return target def url_parse(self, site): """Parse the url into a valid url.""" parse = list( urlparse(site if urlparse(site).scheme else '%s%s' % ('//', site))) parse[0] = b'https' for index, value in enumerate(parse): parse[index] = value.decode('utf-8') if isinstance(value, bytes) \ else value parse = ParseResult(*parse) return parse.geturl()