當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。