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


Python Select.select_by_value方法代码示例

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


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

示例1: fill_payments_form

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
def fill_payments_form(payments_form, 
                       first_name, 
                       last_name, 
                       gender, 
                       phone_number, 
                       email_address, 
#                        birthday_date
                       ):
    """
    Function for fill up payments form.
    Params: 
    # first_name, 
    # last_name, 
    # gender - value "mrs" means female and "mr" means male, 
    # phone_number, 
    # email_address.
    """
#      birthday_date
#     """
    _genders = [u"mrs", u"mr"]
    if not gender in _genders:
        raise Exception('Bad gender value %s - please choose from %s' % (gender, _genders))
    payments_form.find_element_by_id("bookFlight_paxes_1_name").send_keys(first_name)
    payments_form.find_element_by_id("bookFlight_paxes_1_surname").send_keys(last_name)
    gender_select = Select(payments_form.find_element_by_id("bookFlight_paxes_1_title"))
    gender_select.select_by_value(gender)
    payments_form.find_element_by_id("bookFlight_contactDetails_phoneNumber_phoneNumber")\
        .send_keys(phone_number)
    payments_form.find_element_by_id("bookFlight_contactDetails_email").send_keys(email_address)
    payments_form.find_element_by_id("bookFlight_statute").click()
开发者ID:dankon,项目名称:eskypl_tests,代码行数:32,代码来源:eskypl_tests.py

示例2: select_button

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
 def select_button(self, key):
     '''
     运费策略
     '''
     driver = self.conf.driver
     driver.implicitly_wait(10)
     xpath = LC.COMMON[key]
     value = ["0", "1", "2", "3"]
     value0 = random.choice(value)
     number = random.randint(50, 200)
     time.sleep(1)
     ele = Select(driver.find_element_by_xpath(xpath=xpath))
     ele.select_by_value(value0)
     time.sleep(1)
     if value0 == "2":
         # 输入订单的满减金额
         xpath1 = '//*[@id="rule"]/form/div[6]/div/input'
         ele1 = WebDriverWait(driver, 20).until(lambda x: x.find_element_by_xpath(xpath=xpath1))
         time.sleep(1)
         ele1.send_keys(number)
         time.sleep(1)
     elif value0 == "3":
         # 输入订单的满减金额
         xpath2 = '//*[@id="rule"]/form/div[7]/div/input'
         ele1 = WebDriverWait(driver, 20).until(lambda x: x.find_element_by_xpath(xpath=xpath2))
         time.sleep(1)
         ele1.send_keys(number)
         time.sleep(0.5)
     else:
         time.sleep(0.5)
开发者ID:hyteer,项目名称:work,代码行数:32,代码来源:common.py

示例3: select_option_by_value

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
    def select_option_by_value(self, locator, value):
        """
        Selects the option from locator whose value matches the given value

        """
        select = Select(self.driver.find_element(*locator))
        select.select_by_value(value)
开发者ID:Chuwiey,项目名称:modules-activitysnippet,代码行数:9,代码来源:driver.py

示例4: set_select_value

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
 def set_select_value(self, label, value):
     """
     Sets the select with given label (display name) to the specified value
     """
     elem = self.get_setting_element(label)
     select = Select(elem)
     select.select_by_value(value)
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:9,代码来源:library.py

示例5: add

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
    def add(self, username, password, quota=None, filtering=None):
        url = self.live_server_url + reverse('admin:mailboxes_mailbox_add')
        self.selenium.get(url)
        
#        account_input = self.selenium.find_element_by_id('id_account')
#        account_select = Select(account_input)
#        account_select.select_by_value(str(self.account.pk))
        
        name_field = self.selenium.find_element_by_id('id_name')
        name_field.send_keys(username)
        
        password_field = self.selenium.find_element_by_id('id_password1')
        password_field.send_keys(password)
        password_field = self.selenium.find_element_by_id('id_password2')
        password_field.send_keys(password)
        
        if quota is not None:
            quota_id = 'id_resources-resourcedata-content_type-object_id-0-allocated'
            quota_field = self.selenium.find_element_by_id(quota_id)
            quota_field.clear()
            quota_field.send_keys(quota)
        
        if filtering is not None:
            filtering_input = self.selenium.find_element_by_id('id_filtering')
            filtering_select = Select(filtering_input)
            filtering_select.select_by_value("CUSTOM")
            filtering_inline = self.selenium.find_element_by_id('fieldsetcollapser0')
            filtering_inline.click()
            time.sleep(0.5)
            filtering_field = self.selenium.find_element_by_id('id_custom_filtering')
            filtering_field.send_keys(filtering)
        
        name_field.submit()
        self.assertNotEqual(url, self.selenium.current_url)
开发者ID:gmunozc,项目名称:django-orchestra,代码行数:36,代码来源:tests.py

示例6: select_option_by_value

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
def select_option_by_value(browser_query, value):
    """
    Selects a html select element by matching value attribute
    """
    select = Select(browser_query.first.results[0])
    select.select_by_value(value)

    def options_selected():
        """
        Returns True if all options in select element where value attribute
        matches `value`. if any option is not selected then returns False
        and select it. if value is not an option choice then it returns False.
        """
        all_options_selected = True
        has_option = False
        for opt in select.options:
            if opt.get_attribute('value') == value:
                has_option = True
                if not opt.is_selected():
                    all_options_selected = False
                    opt.click()
        # if value is not an option choice then it should return false
        if all_options_selected and not has_option:
            all_options_selected = False
        return all_options_selected

    # Make sure specified option is actually selected
    EmptyPromise(options_selected, "Option is selected").fulfill()
开发者ID:chauhanhardik,项目名称:populo,代码行数:30,代码来源:helpers.py

示例7: fill_form

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
    def fill_form(self, order_id=None, card_type=None,
                  card_number=None, exp_date=None, ccv=None):
        """
        Fills out the Payment Processing Form. Any form fields corresponding to
        ommitted parameters will not be changed.

        :param order_id: The id of the Order you wish to select.
        :param card_type: The string of the type you wish to choose from the 'card_type' select box. Use the visible text of the Card Type you want, not the HTML value of the <option> tag.
        :param card_number: The string you wish to insert into the Card Number field.
        :param exp_date: The string you wish to insert into the Expiration Date field.
        :param ccv: The string you wish to insert into the CCV field.
        """
        if order_id:
            order_select = Select(self.browser.find_element_by_css_selector(self.ORDER_SELECT_SELECTOR))
            order_select.select_by_value(order_id)
        if card_type:
            card_type_select = Select(self.browser.find_element_by_css_selector("select[name='card_type']"))
            card_type_select.select_by_value(card_type)
        if card_number:
            card_number_input = self.browser.find_element_by_css_selector("input[name='card_number']")
            card_number_input.clear()
            card_number_input.send_keys(card_number)
        if exp_date:
            exp_date_input = self.browser.find_element_by_css_selector("input[name='expiration']")
            exp_date_input.clear()
            exp_date_input.send_keys(exp_date)
        if ccv:
            ccv_input = self.browser.find_element_by_css_selector("input[name='ccv']")
            ccv_input.clear()
            ccv_input.send_keys(ccv)
开发者ID:mikedickeyeg,项目名称:egat_example_project,代码行数:32,代码来源:process_payment.py

示例8: add_advanced_filter

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
    def add_advanced_filter(self, key: str, value: str) -> None:
        """Add a new advanced filter"""

        # Toggle the filter panel if it is not open yet
        self.toggle_selected_advanced_filters(display=True)

        # Select the last <select> available
        filter_row_xpath = '(//div[contains(@class, "selected-advanced-filters")]/div[contains(@class, "js-filter-item")])[last()]'
        filter_row = self.findBy('xpath', filter_row_xpath)
        filter_select_xpath = f'//select[contains(@class, "filter-key-select")]'
        select = Select(self.findBy('xpath', filter_select_xpath, base=filter_row))

        # If it already has a key selected, click "add filter" to add a new row
        # and select the <select> again
        if select.first_selected_option.text != '---':
            self.findBy('id', 'filter-add-new').click()
            filter_row = self.findBy('xpath', filter_row_xpath)
            select = Select(
                self.findBy('xpath', filter_select_xpath, base=filter_row))

        # Select the key, wait for the values to be loaded and select one
        select.select_by_value(key)
        self.wait_for('xpath', filter_row_xpath + '//div[contains(@class, "loading-indicator-filter-key")]', visibility=False)
        self.findBy('xpath', f'//div[contains(@class, "filter-value-column")]//input[@value="{value}"]', base=filter_row).click()
        self.apply_filter()
开发者ID:CDE-UNIBE,项目名称:qcat,代码行数:27,代码来源:base.py

示例9: select_from_list

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
 def select_from_list(self, element=None, value=None):
     locator, _type = element
     if not self.wait_element(element):
         allure.attach('screenshot', self.driver.get_screenshot_as_png(), type=AttachmentType.PNG)
         pytest.fail("element {} not found".format(locator))
     select = Select(self.driver.find_element(by=_type, value=locator))
     select.select_by_value(value)
开发者ID:vitekes,项目名称:quotes,代码行数:9,代码来源:WebDriverExt.py

示例10: add

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
    def add(self, name, password, admin_email, address_name=None, address_domain=None):
        url = self.live_server_url + reverse("admin:lists_list_add")
        self.selenium.get(url)

        name_field = self.selenium.find_element_by_id("id_name")
        name_field.send_keys(name)

        password_field = self.selenium.find_element_by_id("id_password1")
        password_field.send_keys(password)
        password_field = self.selenium.find_element_by_id("id_password2")
        password_field.send_keys(password)

        admin_email_field = self.selenium.find_element_by_id("id_admin_email")
        admin_email_field.send_keys(admin_email)

        if address_name:
            address_name_field = self.selenium.find_element_by_id("id_address_name")
            address_name_field.send_keys(address_name)

            domain = Domain.objects.get(name=address_domain)
            domain_input = self.selenium.find_element_by_id("id_address_domain")
            domain_select = Select(domain_input)
            domain_select.select_by_value(str(domain.pk))

        name_field.submit()
        self.assertNotEqual(url, self.selenium.current_url)
开发者ID:glic3rinu,项目名称:django-orchestra,代码行数:28,代码来源:tests.py

示例11: credit_card_payment

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
def credit_card_payment(test, card_type):
    """ Fill payment information
        @param self: Instance of SeleniumTestScript class.
        @param card_type: Type of card used for transaction.
        
    """
    credit_card_number = data.cc["mastercard"]
    # credit_card_code = data.cc_meta[]
    card_code = ""

    # Filling payment details.
    # test.browser.find_element_by_name('TIchoice').click()

    test.browser.find_element_by_id("agi-choice0").click()

    ccname = test.browser.find_element_by_name("ccname")
    ccname.send_keys("test")

    ccnum = test.browser.find_element_by_name("ccnum")
    ccnum.send_keys(credit_card_number)

    cvv2 = test.browser.find_element_by_name("cvv2")
    cvv2.send_keys("334")

    # can possibly get rid of this
    if card_type == "americanexpress":
        card_code = "4444"
    else:
        card_code = "333"

    select = Select(test.browser.find_element_by_id("expiration_month"))
    select.select_by_value("10")

    select = Select(test.browser.find_element_by_id("expiration_year"))
    select.select_by_value("2018")
开发者ID:hbhagwal,项目名称:selenium_test,代码行数:37,代码来源:cc_payment.py

示例12: select_option_with_text

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
    def select_option_with_text(self, select_locator, select_rule, visible_text=None, value=None, wait_timeout=-1):
        """Select the write option in a <select> element

        :param select_locator: the engine to process the rule
        :type select_locator: selenium.webdriver.common.by.By
        :param select_rule: the rule the <select> element must match
        :type select_rule: str
        :param visible_text: the text inside <option> tag. Must be used only if value is None
        :type visible_text: str
        :param value: the text inside value attribute for <option> tag. Must be used only if visible_text is None
        :type value: str
        :param wait_timeout: Number of second that we will poll the DOM. Once this is over, a TimeoutException is raised\
        if wait_timeout is negative, no wait will be processed
        :type wait_timeout: int
        :raises TimeoutException: when wait_timeout is provided and the select element is not found before timeout
        :raises NoSuchElementException: when Select element is not found our there no <option> child matching your \
        requirements
        :raises WebDriverException: when element exist but can't be accessed or when your driver failed to process the \
        selection action
        """
        if value is not None and visible_text is not None:
            raise ValueError("Can't select by visible text AND value")
        if value is None and visible_text is None:
            raise ValueError("You must select by value OR by visible text")
        if wait_timeout < 0:
            select = Select(self.driver.find_element(by=select_locator, value=select_rule))
        else:
            element = WebDriverWait(self.driver, wait_timeout).until(
                EC.element_to_be_clickable((select_locator, select_rule))
            )
            select = Select(element)
        if visible_text is not None:
            select.select_by_visible_text(visible_text)
        if value is not None:
            select.select_by_value(value)
开发者ID:dcolam,项目名称:test-automation-framework,代码行数:37,代码来源:SeleniumWrapper.py

示例13: select_drop_down

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
 def select_drop_down(self, drop_down_locator, value):
     element = self.find_clickable_element(drop_down_locator)
     if element:
         my_select = Select(element)
         my_select.select_by_value(value)
     else:
         raise Exception('Unable to find drop down with locator %s' % str(drop_down_locator))
开发者ID:agustincatalano,项目名称:py_frame,代码行数:9,代码来源:base_page.py

示例14: get_table

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
def get_table(driver):
    form = driver.find_element_by_id('frm_1')
    select = Select(driver.find_element_by_id('sel_court'))
    select.select_by_value('-1') # -1 means all
    # Has no name nor id - have to resort to the fact that it is the only
    # table-like table and thus use a CSS selector
    return driver.find_element_by_css_selector('table.standard_table')
开发者ID:jrtc27,项目名称:mytrin-ballot,代码行数:9,代码来源:scrape.py

示例15: swap_user

# 需要导入模块: from selenium.webdriver.support.select import Select [as 别名]
# 或者: from selenium.webdriver.support.select.Select import select_by_value [as 别名]
 def swap_user(self, username, username2, dbname):
     database = Database.objects.get(name=dbname, type=self.db_type)
     url = self.live_server_url + change_url(database)
     self.selenium.get(url)
     
     # remove user "username"
     user = DatabaseUser.objects.get(username=username, type=self.db_type)
     users_to = self.selenium.find_element_by_id('id_users_to')
     users_select = Select(users_to)
     users_select.select_by_value(str(user.pk))
     remove_user = self.selenium.find_element_by_id('id_users_remove_link')
     remove_user.click()
     time.sleep(0.2)
     
     # add user "username2"
     user = DatabaseUser.objects.get(username=username2, type=self.db_type)
     users_from = self.selenium.find_element_by_id('id_users_from')
     users_select = Select(users_from)
     users_select.select_by_value(str(user.pk))
     add_user = self.selenium.find_element_by_id('id_users_add_link')
     add_user.click()
     time.sleep(0.2)
     
     save = self.selenium.find_element_by_name('_save')
     save.submit()
     self.assertNotEqual(url, self.selenium.current_url)
开发者ID:SCORE42,项目名称:django-orchestra,代码行数:28,代码来源:tests.py


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