当前位置: 首页>>代码示例>>Python>>正文


Python By.ID属性代码示例

本文整理汇总了Python中selenium.webdriver.common.by.By.ID属性的典型用法代码示例。如果您正苦于以下问题:Python By.ID属性的具体用法?Python By.ID怎么用?Python By.ID使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在selenium.webdriver.common.by.By的用法示例。


在下文中一共展示了By.ID属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: submit_user_data

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def submit_user_data(self):
        # Submit to Authent-Number Page (press button).
        wait = WebDriverWait(self.driver, timeout=6)
        try:
            self.driver.execute_script(
                'document.getElementsByTagName("button")[0].click()'
            )
            wait.until(
                EC.presence_of_element_located(
                    (By.ID, 'idRandomPic')
                )
            )
        except:
            self.label_show_result.setText(
                '【連線逾時或是網路不穩定】\n' + 
                '【請檢查網路環境以及是否為尖峰時段。】'
            ) 
开发者ID:gw19,项目名称:TRA-Ticket-Booker,代码行数:19,代码来源:TraTicketBooker.py

示例2: index_page

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def index_page(page):
    try:
        print('正在爬取第: %s 页' % page)
        wait.until(
            EC.presence_of_element_located((By.ID, "dt_1")))
        # 判断是否是第1页,如果大于1就输入跳转,否则等待加载完成。
        if page > 1:
            # 确定页数输入框
            input = wait.until(EC.presence_of_element_located(
                (By.XPATH, '//*[@id="PageContgopage"]')))
            input.click()
            input.clear()
            input.send_keys(page)
            submit = wait.until(EC.element_to_be_clickable(
                (By.CSS_SELECTOR, '#PageCont > a.btn_link')))
            submit.click()
            time.sleep(2)
        # 确认成功跳转到输入框中的指定页
        wait.until(EC.text_to_be_present_in_element(
            (By.CSS_SELECTOR, '#PageCont > span.at'), str(page)))
    except Exception:
        return None 
开发者ID:makcyun,项目名称:eastmoney_spider,代码行数:24,代码来源:eastmoney_crawler.py

示例3: __login

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def __login(self):
        if self.debug: self.driver.save_screenshot(self.directory + r'01.png')
        txt_login = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_txtLogin')
        txt_login.clear()
        txt_login.send_keys(os.environ['CPF'])

        time.sleep(3.0)
        txt_senha = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_txtSenha')
        txt_senha.clear()
        txt_senha.send_keys(os.environ['SENHA_CEI'])
        time.sleep(3.0)

        if self.debug: self.driver.save_screenshot(self.directory + r'02.png')

        btn_logar = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_btnLogar')
        btn_logar.click()

        try:
            WebDriverWait(self.driver, 60).until(EC.visibility_of_element_located((By.ID, 'objGrafPosiInv')))
        except Exception as ex:
            raise Exception('Nao foi possivel logar no CEI. Possivelmente usuario/senha errada ou indisponibilidade do site')

        if self.debug: self.driver.save_screenshot(self.directory + r'03.png') 
开发者ID:guilhermecgs,项目名称:ir,代码行数:25,代码来源:crawler_cei.py

示例4: __recupera_tipo_ticker

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def __recupera_tipo_ticker(self):
        WebDriverWait(CrawlerAdvfn.driver, 10).until(EC.visibility_of_element_located((By.ID, 'quoteElementPiece5')))
        tipo = CrawlerAdvfn.driver.find_element_by_id('quoteElementPiece5').text.lower()

        if tipo == 'futuro':
            return TipoTicker.FUTURO

        if tipo == 'opção':
            return TipoTicker.OPCAO

        if tipo == 'preferencial' or tipo == 'ordinária':
            return TipoTicker.ACAO

        if tipo == 'fundo':
            if self.__fundo_eh_fii():
                return TipoTicker.FII

            if self.__fundo_eh_etf():
                return TipoTicker.ETF

        return None 
开发者ID:guilhermecgs,项目名称:ir,代码行数:23,代码来源:crawler_advfn.py

示例5: participate

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def participate(self):
        random.seed(self.worker_id)
        chatbot = random.choice(self.PERSONALITIES)
        WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.ID, "send-message"))
        )
        logger.info("Entering participate method")
        start = time.time()
        while (time.time() - start) < self.TOTAL_CHAT_TIME:

            self.wait_to_send_message()
            history = self.get_chat_history()
            logger.info("History: %s" % history)
            if history and history[-1]:
                logger.info("Responding to: %s" % history[-1])
                output = chatbot.respond(history[-1])
            else:
                logger.info("Using random greeting.")
                output = random.choice(self.GREETINGS)
            logger.info("Output: %s" % output)
            self.send_message(output)

        self.leave_chat() 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:25,代码来源:bots.py

示例6: sign_off

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def sign_off(self):
        """Submit questionnaire and finish.

        This uses Selenium to click the submit button on the questionnaire
        and return to the original window.
        """
        try:
            logger.info("Bot player signing off.")
            feedback = WebDriverWait(self.driver, 20).until(
                EC.presence_of_element_located((By.ID, "submit-questionnaire"))
            )
            self.complete_questionnaire()
            feedback.click()
            logger.info("Clicked submit questionnaire button.")
            self.driver.switch_to_window(self.driver.window_handles[0])
            self.driver.set_window_size(1024, 768)
            logger.info("Switched back to initial window.")
            return True
        except TimeoutException:
            logger.error("Error during experiment sign off.")
            return False 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:23,代码来源:bots.py

示例7: wait_for_text

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def wait_for_text(driver, el_id, value, removed=False, timeout=10):
    el = wait_for_element(driver, el_id, timeout)
    if value in el.text and not removed:
        return el
    if removed and value not in el.text:
        return el

    wait = WebDriverWait(driver, timeout)
    condition = EC.text_to_be_present_in_element((By.ID, el_id), value)
    if removed:
        wait.until_not(condition)
        if value not in el.text:
            return el
    else:
        wait.until(condition)
        if value in el.text:
            return el

    raise AttributeError 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:21,代码来源:pytest_dallinger.py

示例8: test_08_invalid_trans_id

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def test_08_invalid_trans_id(self, base_url, selenium):
        self.get(selenium, base_url + '/reconcile')
        assert self.get_reconciled(selenium) == {}
        script = 'reconciled[1234] = [4, "OFXNONE"];'
        selenium.execute_script(script)
        assert self.get_reconciled(selenium) == {
            1234: [4, "OFXNONE"]
        }
        # click submit button
        selenium.find_element_by_id('reconcile-submit').click()
        sleep(1)
        self.wait_for_jquery_done(selenium)
        assert self.get_reconciled(selenium) == {
            1234: [4, "OFXNONE"]
        }
        msg = selenium.find_element_by_id('reconcile-msg')
        assert msg.text == 'Error 400: Invalid Transaction ID: 1234'
        assert 'alert-danger' in msg.get_attribute('class') 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:20,代码来源:test_reconcile.py

示例9: wait_until_clickable

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def wait_until_clickable(self, driver, elem_id, by=By.ID, timeout=10):
        """
        Wait for the modal to be shown.

        :param driver: Selenium driver instance
        :type driver: selenium.webdriver.remote.webdriver.WebDriver
        :param elem_id: element ID
        :type elem_id: str
        :param by: What method to use to find the element. This must be one of
          the strings which are values of
          :py:class:`selenium.webdriver.common.by.By` attributes.
        :type by: str
        :param timeout: timeout in seconds
        :type timeout: int
        """
        WebDriverWait(driver, timeout).until(
            EC.element_to_be_clickable((by, elem_id))
        ) 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:20,代码来源:acceptance_helpers.py

示例10: SwitchModal

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def SwitchModal(self, option, frame=''):
        '''
        Sets the focus in a modal object
        '''
        try:
            time.sleep(2)
            self.driver.switch_to.default_content()
            self.driver.implicitly_wait(30)
            modaldupGuia = self.wait.until(EC.presence_of_element_located((By.ID, "modal-content")))

            if modaldupGuia.is_displayed():
                btn = self.driver.find_element_by_xpath("//button[contains(text(), '%s')]" % option)
                btn.click()
            else:
                time.sleep(2)
                if modaldupGuia.is_displayed():
                    btn = self.driver.find_element_by_xpath("//button[contains(text(), '%s')]" % option)
                    btn.click()
        except Exception as e:
            self.log_error(str(e)) 
开发者ID:totvs,项目名称:tir,代码行数:22,代码来源:apw_internal.py

示例11: get_web_value

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def get_web_value(self, element):
        """
		Gets the informations of field based in the ID
        """

        if element.tag_name == "div":
            element_children = element.find_element(By.CSS_SELECTOR, "div > * ")
            if element_children is not None:
                element = element_children

        if element.tag_name == "label":
            web_value = element.get_attribute("text")
        elif element.tag_name == "select":
            current_select = int(element.get_attribute('value'))
            selected_element = element.find_elements(By.CSS_SELECTOR, "option")[current_select]
            web_value = selected_element.text
        else:
            web_value = element.get_attribute("value")

        return web_value 
开发者ID:totvs,项目名称:tir,代码行数:22,代码来源:apw_internal.py

示例12: start_captcha

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def start_captcha():
    driver = webdriver.Firefox()
    driver.get("http://reddit.com")
    driver.find_element(By.XPATH, "//*[@id=\"header-bottom-right\"]/span[1]/a").click()
    time.sleep(1)
    driver.find_element(By.ID, "user_reg").send_keys("qwertyuiop091231")
    driver.find_element(By.ID, "passwd_reg").send_keys("THISISMYPASSWORD!!$")
    driver.find_element(By.ID, "passwd2_reg").send_keys("THISISMYPASSWORD!!$")
    driver.find_element(By.ID, "email_reg").send_keys("biggie.smalls123@gmail.com")
    #driver.find_element_by_tag_name("body").send_keys(Keys.COMMAND + Keys.ALT + 'k')
    iframeSwitch = driver.find_element(By.XPATH, "//*[@id=\"register-form\"]/div[6]/div/div/div/iframe")
    driver.switch_to.frame(iframeSwitch)
    driver.find_element(By.ID, "recaptcha-anchor").click()
    # download captcha image
    # 
    # split payload
    # 
    # reverse_search
    # 
    # driver.quit()

# determines if an image keywords matches the target keyword
# uses the synonyms of the image keyword 
开发者ID:ecthros,项目名称:uncaptcha,代码行数:25,代码来源:ris.py

示例13: close_letter

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def close_letter(self):
        # If we are at specific letter, press the "go back" button.
        elems = self.worker.all(By.CSS_SELECTOR, '.pageTitle')
        if len(elems) != 0:
            title = elems[0].text.strip()
            if title == 'Configuration File':
                try:
                    backBtn = self.worker.first(By.ID, 'PAGE_BUTTONS_cbuttonback')
                    backBtn.click()
                except NoSuchElementException:
                    pass
                try:
                    backBtn = self.worker.first(By.ID, 'PAGE_BUTTONS_cbuttonnavigationcancel')
                    backBtn.click()
                except NoSuchElementException:
                    pass

            self.worker.wait_for(By.CSS_SELECTOR, '#TABLE_DATA_fileList') 
开发者ID:scriptotek,项目名称:alma-slipsomat,代码行数:20,代码来源:slipsomat.py

示例14: pass_check

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def pass_check(self):
        no_7 = self.driver.find_element(value="digit_7", by=By.ID)
        no_7.click();
        plus = self.driver.find_element(value="op_add", by=By.ID)
        plus.click();
        no_4 = self.driver.find_element(value="digit_4", by=By.ID)
        no_4.click();
        equalTo = self.driver.find_element(value="eq", by=By.ID)
        equalTo.click();
        results = self.driver.find_element(value="formula", by=By.ID)
        result_value = results.get_attribute('text')
        if result_value == '11':
            self.passed('Value is 11')
        else:
            self.failed('Value is not 11')

    # Second test section 
开发者ID:CiscoTestAutomation,项目名称:solutions_examples,代码行数:19,代码来源:pyats_android.py

示例15: failure_check

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import ID [as 别名]
def failure_check(self):
        no_7 = self.driver.find_element(value="digit_7", by=By.ID)
        no_7.click();
        plus = self.driver.find_element(value="op_add", by=By.ID)
        plus.click();
        no_4 = self.driver.find_element(value="digit_4", by=By.ID)
        no_4.click();
        equalTo = self.driver.find_element(value="eq", by=By.ID)
        equalTo.click();

        results = self.driver.find_element(value="formula", by=By.ID)
        result_value = results.get_attribute('text')
        if result_value == '12':
            self.passed('Value is 12')
        else:
            self.failed('Value is not 12') 
开发者ID:CiscoTestAutomation,项目名称:solutions_examples,代码行数:18,代码来源:pyats_android.py


注:本文中的selenium.webdriver.common.by.By.ID属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。