slipsomat.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:alma-slipsomat 作者: scriptotek 项目源码 文件源码
def connect(self):
        domain = self.config.get('login', 'domain')
        auth_type = self.config.get('login', 'auth_type')
        institution = self.config.get('login', 'institution')
        username = self.config.get('login', 'username')
        password = self.config.get('login', 'password')

        self.driver = self.get_driver()
        self.driver.set_window_size(self.config.get('window', 'width'),
                                    self.config.get('window', 'height'))
        self.wait = self.waiter()

        print('Opening instance {}:{}'.format(self.instance, institution))

        self.get('/mng/login?institute={}&auth={}'.format(institution, auth_type))

        if auth_type == 'SAML' and domain != '':
            print('Logging in as {}@{}'.format(username, domain))

            element = self.wait.until(EC.visibility_of_element_located((By.ID, 'org')))
            select = Select(element)
            select.select_by_value(domain)

            element = self.driver.find_element_by_id('submit')
            element.click()
            # We cannot use submit() because of
            # http://stackoverflow.com/questions/833032/submit-is-not-a-function-error-in-javascript
        else:
            print('Logging in as {}'.format(username))

        self.send_keys(By.ID, 'username', username)
        element = self.send_keys(By.ID, 'password', password)
        element.send_keys(Keys.RETURN)

        try:
            # Look for some known element on the Alma main screen
            self.wait_for(By.CSS_SELECTOR, '.logoAlma', 30)
        except NoSuchElementException:
            raise Exception('Failed to login to Alma')

        print("login DONE")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号