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


Python By.NAME属性代码示例

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


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

示例1: test_stick_to_top_admin

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def test_stick_to_top_admin(self):
        self.browser.get(self.live_server_url + reverse("niji:index"))
        login(self.browser, 'super', '123')
        self.assertIn("Log out", self.browser.page_source)

        lucky_topic1 = getattr(self, 't%s' % random.randint(1, 50))

        self.browser.get(self.live_server_url+reverse('niji:topic', kwargs={"pk": lucky_topic1.pk}))
        self.browser.find_element_by_class_name('move-topic-up').click()
        up_level = WebDriverWait(
            self.browser, 10
        ).until(
            expected_conditions.presence_of_element_located(
                (By.NAME, 'move-topic-up-level')
            )
        )
        up_level = Select(up_level)
        up_level.select_by_visible_text('1')
        time.sleep(1)
        self.browser.execute_script("$('.modal-confirm').click()")
        self.browser.get(self.live_server_url+reverse('niji:index'))
        first_topic_title = self.browser.find_elements_by_class_name('entry-link')[0].text

        self.assertEqual(first_topic_title, lucky_topic1.title) 
开发者ID:ericls,项目名称:niji,代码行数:26,代码来源:tests.py

示例2: submit_login

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def submit_login(self, username, password):

        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located((By.NAME, "username")))
        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located((By.NAME, "password")))
        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located(
                (By.XPATH, '//input[@type="submit"]')))

        username_input = self.selenium.find_element_by_name("username")
        username_input.send_keys(username)
        password_input = self.selenium.find_element_by_name("password")
        password_input.send_keys(password)

        self.selenium.find_element_by_xpath('//input[@type="submit"]').click()

        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located(
                (By.XPATH, '//div[@class="jumbotron"]')))
        import time
        time.sleep(2) 
开发者ID:SaturdayNeighborhoodHealthClinic,项目名称:osler,代码行数:24,代码来源:test.py

示例3: find_element

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def find_element(driver, timeout_seconds, mode, xpath):
    if mode == "NAME":
        return WebDriverWait(driver, timeout_seconds).until(
            EC.visibility_of_element_located((By.NAME, xpath))
        )
    elif mode == "ID":
        return WebDriverWait(driver, timeout_seconds).until(
            EC.visibility_of_element_located((By.ID, xpath))
        )
    elif mode == "CLASS_NAME":
        return WebDriverWait(driver, timeout_seconds).until(
            EC.visibility_of_element_located((By.CLASS_NAME, xpath))
        )
    else:
        return WebDriverWait(driver, timeout_seconds).until(
            EC.visibility_of_element_located((By.XPATH, xpath))
        ) 
开发者ID:intuit,项目名称:automation-for-humans,代码行数:19,代码来源:common.py

示例4: _driver_brute

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def _driver_brute(self, username: str, pwd_guess: str) -> str:
        """
        Uses a Firefox-based webdriver in order to attempt authentication by
        spawning actual browser processes. Should be used in the situation that
        the headless run does not yield anything successful, and more visibility is needed.
        """

        # find the username input field, and send keys
        user_elem = self.browser.find_element(By.NAME, self.fields["username"])  # type: ignore
        user_elem.clear()
        user_elem.send_keys(username)

        # find the password input field, and send keys
        pwd_elem = self.browser.find_element(By.NAME, self.fields["password"])  # type: ignore
        pwd_elem.clear()
        pwd_elem.send_keys(pwd_guess)

        # press return key to attempt to auth, and wait briefly
        pwd_elem.send_keys(Keys.RETURN)
        time.sleep(2)
        return self.browser.title 
开发者ID:ex0dus-0x,项目名称:brute,代码行数:23,代码来源:web.py

示例5: add_videos

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def add_videos(self, driver, title_, videopath):
        WebDriverWait(driver, 20).until(
            ec.presence_of_element_located((By.NAME, 'buploader')))
        upload = driver.find_element_by_name('buploader')
        # print(driver.title)
        # logger.info(driver.title)
        upload.send_keys(videopath)  # send_keys
        logger.info('开始上传' + title_)
        time.sleep(2)
        button = r'//*[@class="new-feature-guide-v2-container"]/div/div/div/div/div[1]'
        if self.is_element_exist(driver, button):
            sb = driver.find_element_by_xpath(button)
            sb.click()
            sb.click()
            sb.click()
            logger.debug('点击')
        while True:
            try:
                info = driver.find_elements_by_class_name(r'item-upload-info')
                for t in info:
                    if t.text != '':
                        print(t.text)
                time.sleep(10)
                text = driver.find_elements_by_xpath(r'//*[@class="item-upload-info"]/span')
                aggregate = set()
                for s in text:
                    if s.text != '':
                        aggregate.add(s.text)
                        print(s.text)

                if len(aggregate) == 1 and ('Upload complete' in aggregate or '上传完成' in aggregate):
                    break
            except selenium.common.exceptions.StaleElementReferenceException:
                logger.exception("selenium.common.exceptions.StaleElementReferenceException")
        logger.info('上传%s个数%s' % (title_, len(info))) 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:37,代码来源:upload.py

示例6: get_token

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def get_token(self, url):
        token = ''
        path = os.getcwd()
        if _platform == "Windows" or _platform == "win32":
            # Check if we are on 32 or 64 bit
            file_name= 'chromedriver.exe'
        if _platform.lower() == "darwin":
            file_name= 'chromedriver'
        if _platform.lower() == "linux" or _platform.lower() == "linux2":
            file_name = 'chromedriver'
            
        full_path = ''
        if os.path.isfile(path + '/' + file_name): # check local dir first
            full_path = path + '/' + file_name

        if full_path == '':
            self.bot.logger.error(file_name + ' is needed for manual captcha solving! Please place it in the bots root directory')
            sys.exit(1)
        
        try:
            driver = webdriver.Chrome(full_path)
            driver.set_window_size(600, 600)
        except Exception:
            self.bot.logger.error('Error with Chromedriver, please ensure it is the latest version.')
            sys.exit(1)
            
        driver.get(url)
        
        elem = driver.find_element_by_class_name("g-recaptcha")
        driver.execute_script("arguments[0].scrollIntoView(true);", elem)
        self.bot.logger.info('You have 1 min to solve the Captcha')
        try:
            WebDriverWait(driver, 60).until(EC.text_to_be_present_in_element_value((By.NAME, "g-recaptcha-response"), ""))
            token = driver.execute_script("return grecaptcha.getResponse()")
            driver.close()
        except TimeoutException, err:
            self.bot.logger.error('Timed out while trying to solve captcha') 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:39,代码来源:captcha_handler.py

示例7: find_element

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def find_element(self, by: str = By.ID, value: Union[str, Dict] = None) -> T:
        """Find an element given a By strategy and locator

        Override for Appium

        Prefer the find_element_by_* methods when possible.

        Args:
            by: The strategy
            value: The locator

        Usage:
            element = element.find_element(By.ID, 'foo')

        Returns:
            `appium.webdriver.webelement.WebElement`
        """
        # TODO: If we need, we should enable below converter for Web context
        # if self._w3c:
        #     if by == By.ID:
        #         by = By.CSS_SELECTOR
        #         value = '[id="%s"]' % value
        #     elif by == By.TAG_NAME:
        #         by = By.CSS_SELECTOR
        #     elif by == By.CLASS_NAME:
        #         by = By.CSS_SELECTOR
        #         value = ".%s" % value
        #     elif by == By.NAME:
        #         by = By.CSS_SELECTOR
        #         value = '[name="%s"]' % value

        return self._execute(RemoteCommand.FIND_CHILD_ELEMENT,
                             {"using": by, "value": value})['value'] 
开发者ID:appium,项目名称:python-client,代码行数:35,代码来源:webelement.py

示例8: find_elements

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def find_elements(self, by: str = By.ID, value: Union[str, Dict] = None) -> List[T]:
        """Find elements given a By strategy and locator

        Override for Appium

        Prefer the find_elements_by_* methods when possible.

        Args:
            by: The strategy
            value: The locator

        Usage:
            element = element.find_elements(By.CLASS_NAME, 'foo')

        Returns:
            :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`
        """
        # TODO: If we need, we should enable below converter for Web context
        # if self._w3c:
        #     if by == By.ID:
        #         by = By.CSS_SELECTOR
        #         value = '[id="%s"]' % value
        #     elif by == By.TAG_NAME:
        #         by = By.CSS_SELECTOR
        #     elif by == By.CLASS_NAME:
        #         by = By.CSS_SELECTOR
        #         value = ".%s" % value
        #     elif by == By.NAME:
        #         by = By.CSS_SELECTOR
        #         value = '[name="%s"]' % value

        return self._execute(RemoteCommand.FIND_CHILD_ELEMENTS,
                             {"using": by, "value": value})['value'] 
开发者ID:appium,项目名称:python-client,代码行数:35,代码来源:webelement.py

示例9: find_element

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def find_element(self, by: str = By.ID, value: Union[str, Dict] = None) -> MobileWebElement:
        """'Private' method used by the find_element_by_* methods.

        Override for Appium

        Usage:
            Use the corresponding find_element_by_* instead of this.

        Returns:
            `appium.webdriver.webelement.WebElement`: The found element

        """
        # TODO: If we need, we should enable below converter for Web context
        # if self.w3c:
        #     if by == By.ID:
        #         by = By.CSS_SELECTOR
        #         value = '[id="%s"]' % value
        #     elif by == By.TAG_NAME:
        #         by = By.CSS_SELECTOR
        #     elif by == By.CLASS_NAME:
        #         by = By.CSS_SELECTOR
        #         value = ".%s" % value
        #     elif by == By.NAME:
        #         by = By.CSS_SELECTOR
        #         value = '[name="%s"]' % value

        return self.execute(RemoteCommand.FIND_ELEMENT, {
            'using': by,
            'value': value})['value'] 
开发者ID:appium,项目名称:python-client,代码行数:31,代码来源:webdriver.py

示例10: find_elements

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def find_elements(self, by: str = By.ID, value: Union[str, Dict]
                      = None) -> Union[List[MobileWebElement], List]:
        """'Private' method used by the find_elements_by_* methods.

        Override for Appium

        Usage:
            Use the corresponding find_elements_by_* instead of this.

        Returns:
            :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
        """
        # TODO: If we need, we should enable below converter for Web context
        # if self.w3c:
        #     if by == By.ID:
        #         by = By.CSS_SELECTOR
        #         value = '[id="%s"]' % value
        #     elif by == By.TAG_NAME:
        #         by = By.CSS_SELECTOR
        #     elif by == By.CLASS_NAME:
        #         by = By.CSS_SELECTOR
        #         value = ".%s" % value
        #     elif by == By.NAME:
        #         by = By.CSS_SELECTOR
        #         value = '[name="%s"]' % value

        # Return empty list if driver returns null
        # See https://github.com/SeleniumHQ/selenium/issues/4555

        return self.execute(RemoteCommand.FIND_ELEMENTS, {
            'using': by,
            'value': value})['value'] or [] 
开发者ID:appium,项目名称:python-client,代码行数:34,代码来源:webdriver.py

示例11: fill_form

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def fill_form(self, form_data, validate_fields=None):
        """
        Fill in the form with the given data.
        """
        validate_fields = validate_fields or ()
        for field, value in form_data.items():
            element = self.form.find_element_by_name(field)
            if element.get_attribute('type') == 'checkbox':
                if bool(value) != element.is_selected():
                    element.click()
                    # Before moving on, make sure checkbox state (checked/unchecked) corresponds to desired value
                    WebDriverWait(self.client, timeout=5) \
                        .until(expected_conditions.element_selection_state_to_be(element, value))
                continue

            if element.get_attribute('type') == 'color':
                # Selenium doesn't support typing into HTML5 color field with send_keys
                id_elem = element.get_attribute('id')
                self.client.execute_script("document.getElementById('{}').type='text'".format(id_elem))

            if not element.get_attribute('readonly') and not element.get_attribute('type') == 'hidden':
                element.clear()
                if value:
                    # A small delay is required for angular to properly mark field as dirty
                    element.click()
                    time.sleep(.5)
                    element.send_keys(value)
                    # Before moving on, make sure input field contains desired text
                    WebDriverWait(self.client, timeout=5) \
                        .until(expected_conditions.text_to_be_present_in_element_value((By.NAME, field), value))
                    # And that the server validation, if any, has completed
                    if field in validate_fields:
                        WebDriverWait(self.client, timeout=10) \
                            .until(ServerValidationComplete((By.NAME, field))) 
开发者ID:open-craft,项目名称:opencraft,代码行数:36,代码来源:utils.py

示例12: waitForSignInEmailElementByName

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def waitForSignInEmailElementByName(self):
        return WebDriverWait(self.driver, self.timeout).until(
            EC.presence_of_element_located((By.NAME, 'email'))
        ) 
开发者ID:ab77,项目名称:netflix-proxy,代码行数:6,代码来源:testvideo.py

示例13: waitForSignInPasswordElementByName

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def waitForSignInPasswordElementByName(self):
        return WebDriverWait(self.driver, self.timeout).until(
            EC.presence_of_element_located((By.NAME, 'password'))
        ) 
开发者ID:ab77,项目名称:netflix-proxy,代码行数:6,代码来源:testvideo.py

示例14: _process_survey_age_country

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def _process_survey_age_country(self):
        try:
            print("* They want to know how old we are.")
            age_field = self.wait.until(EC.element_to_be_clickable(
                (By.NAME, 'rpAgeAndCountryAgeField')))
            age_field.send_keys('55')
            age_field.send_keys(Keys.RETURN)

            # wait for age_field's DOM element to be removed
            self.wait.until(EC.staleness_of(age_field))
        except TimeoutException:
            print("!!! Something's wrong with the survey") 
开发者ID:bittner,项目名称:lego-mindstorms-ev3-comparison,代码行数:14,代码来源:legoshop.py

示例15: check_eyes_region_by_element

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import NAME [as 别名]
def check_eyes_region_by_element(self, selector, value, name, includeEyesLog=False, httpDebugLog=False):
        """
        Takes a snapshot of the region of the given selector and element value from the browser using the web driver
        and matches it with the expected output. With a choice from four selectors, listed below, to check by.

        Arguments:
                |  Selector (string)                | This will decide what element will be located. The supported selectors include: XPATH, ID, CLASS NAME, CSS SELECTOR  |
                |  Value (string)                   | The specific value of the selector. e.g. an xpath value //*[@id="navbar"]/div/div                                    |
                |  Name (string)                    | Name that will be given to region in Eyes.                                                                           |
                |  Include Eyes Log (default=False) | The Eyes logs will not be included by default. To activate, pass 'True' in the variable.                             |
                |  HTTP Debug Log (default=False)   | The HTTP Debug logs will not be included by default. To activate, pass 'True' in the variable.                       |
        Example:

        | *Keywords*                    |  *Parameters*                                                                                                    |
        | Open Browser                  |  http://www.navinet.net/  |  gc                |                             |                    |       |      |
        | Open Eyes Session             |  http://www.navinet.net/  |  RobotAppEyes_Test |  NaviNet_RobotAppEyes_Test  |  YourApplitoolsKey |  1024 |  768 |
        | Check Eyes Region By Element  |  CLASS NAME               |  container         |  NaviNetClassElement        |                    |       |      |
        | Close Eyes Session            |  False                    |                    |                             |                    |       |      |

        """
        if includeEyesLog is True:
            logger.set_logger(StdoutLogger())
            logger.open_()
        if httpDebugLog is True:
            httplib.HTTPConnection.debuglevel = 1

        searchElement = None

        if selector.upper() == 'XPATH':
            searchElement = driver.find_element_by_xpath(value)
        elif selector.upper() == 'ID':
            searchElement = driver.find_element_by_id(value)
        elif selector.upper() == 'CLASS NAME':
            searchElement = driver.find_element_by_class_name(value)
        elif selector.upper() == 'CSS SELECTOR':
            searchElement = driver.find_element_by_css_selector(value)
        else:
            raise InvalidElementStateException('Please select a valid selector: XPATH, ID, CLASS NAME, CSS SELECTOR')
        eyes.check_region_by_element(searchElement, name) 
开发者ID:NaviNet,项目名称:Robot-AppEyes,代码行数:41,代码来源:RobotAppEyes.py


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