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)
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)
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)
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)
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()
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)
def test_user_preferences(self): unsigned_url = self.live_server_url + reverse('notification_preferences') self.browser.get(unsigned_url) # ah, a login is required self.assertEqual( self.findBy('class_name', 'is-title').text, 'Login' ) self.doLogin(user=self.user) # after the login, the preferences are shown self.browser.get(unsigned_url) # without changing anything, the form is submitted self.findBy('xpath', '//input[@type="submit"]').click() # and still, the url without signed id is used. self.assertEqual( self.browser.current_url, unsigned_url + '#' ) # jay now changes the language and saves again. select = Select(self.findBy('id', 'id_language')) select.select_by_value('es') self.findBy('xpath', '//input[@type="submit"]').click() # after the success message is shown, the flag is set that the language # is not overridden anymore. self.wait_for('class_name', 'notification') self.assertTrue( MailPreferences.objects.get(user__firstname='jay').has_changed_language )
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()
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)
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)
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)
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")
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)
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))
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')
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()
def select_dd_course(self, course): try: dd_element = Select(self.dd_course) dd_element.select_by_value(course) logger.info('Corse {0} was selected' .format(course)) except Exception as exc: logger.error('dd_course - {0}' .format(exc)) raise exc
def update_select(el, value, by_text=False): select = Select(el) if value == '': select.select_by_index(0) elif by_text: select.select_by_visible_text(value) else: select.select_by_value(value)
def select(self, selectLocator, optionLocator): el = self.driver.find_element(self.getBy(selectLocator), self.getValue(selectLocator)) select = Select(el) logging.debug(select.options) if "label=" in optionLocator: select.select_by_visible_text(optionLocator[6:]) elif "value=" in optionLocator: select.select_by_value(optionLocator[6:])
def create_new_program(self, program_name, program_subtitle, program_marketing_slug): self.q(css='input#program-name').fill(program_name) self.q(css='input#program-subtitle').fill(program_subtitle) self.q(css='input#program-marketing-slug').fill(program_marketing_slug) select = Select(self.browser.find_element_by_css_selector('select#program-org')) select.select_by_value(PROGRAM_ORGANIZATION) # Click on create program button to create the new program self.q(css='button.js-create-program').first.click()
def fill_create_coupon_form(self, is_discount): """ Fills the coupon form with test data and creates the coupon. Args: is_discount(bool): Indicates if the code that's going to be created should be a discount or enrollment coupon code. Returns: coupon_name(str): Fuzzied name of the coupon that has been created. """ course_id_input = 'input[name="course_id"]' coupon_name = _get_coupon_name(is_discount) self.q(css='input[name="title"]').fill(coupon_name) self.q(css=course_id_input).fill(VERIFIED_COURSE_ID) self.wait_for_ajax() wait = WebDriverWait(self.browser, 2) verified_option_present = EC.presence_of_element_located( (By.CSS_SELECTOR, 'select[name="seat_type"] option[value="Verified"]') ) wait.until(verified_option_present) self.q(css="input[name='start_date']").fill(str(DEFAULT_START_DATE)) self.q(css="input[name='end_date']").fill(str(DEFAULT_END_DATE)) self.q(css="input[name='client']").fill('Test Client') select = Select(self.browser.find_element_by_css_selector('select[name="seat_type"]')) select.select_by_value('Verified') # Prevent the test from advancing before the seat type is selected. wait = WebDriverWait(self.browser, 2) verified_option_selected = option_selected(select, 'Verified') wait.until(verified_option_selected) select = Select(self.browser.find_element_by_css_selector('select[name="code_type"]')) select.select_by_value('Discount code') wait = WebDriverWait(self.browser, 2) benefit_input_present = EC.presence_of_element_located((By.CSS_SELECTOR, 'input[name="benefit_value"]')) wait.until(benefit_input_present) self.q(css="input[name='code']").fill(CODE) if is_discount: self.q(css="input[name='benefit_value']").fill('50') else: self.q(css="input[name='benefit_value']").fill('100') self.q(css="input[name='invoice_number']").fill('1001') self.q(css="input[name='invoice_payment_date']").fill(str(DEFAULT_END_DATE)) self.q(css="input[name='price']").fill('100') self.q(css="div.form-actions > button.btn").click() self.wait_for_ajax() return coupon_name
def setUpClass(cls): cls.driver = webdriver.Firefox() time.sleep(11) cls.driver.maximize_window() cls.driver.get("http://10.240.12.168/tts-HTS/") time.sleep(5) iSelect = Select(cls.driver.find_element_by_xpath(".//*[@id='AutoNumber1']/tbody/tr[1]/td[2]/select")) iSelect.select_by_value("voice4") time.sleep(2)
def login(): #Edit the login process for your school, mine is UIUC driver.get(__MAINURL__) select = Select(driver.find_element(By.XPATH,'//div[@id="shibboleth-box"]/select')) select.select_by_value('urn%3Amace%3Aincommon%3Auiuc.edu') driver.find_element(By.XPATH,'//div[@id="login-submit-button"]/button').click() driver.find_element(By.XPATH,'//input[@id="j_username"]').send_keys(__USERNAME__) driver.find_element(By.XPATH,'//input[@id="j_password"]').send_keys(__PASSWORD__) driver.find_element(By.XPATH,'//div[@id="submit_button"]/input').click() time.sleep(5)
def capa_type(self, value): """ Sets value of CAPA type select """ select_element = self.get_metadata_input(self.PROBLEM_TYPE_LABEL) select_element.click() problem_type_select = Select(select_element) problem_type_select.select_by_value(value) EmptyPromise(lambda: self.capa_type == value, "problem type is updated in modal.").fulfill()
def scored(self, scored): """ Sets value of scored select """ select_element = self.get_metadata_input(self.SCORED_LABEL) select_element.click() scored_select = Select(select_element) scored_select.select_by_value(str(scored)) EmptyPromise(lambda: self.scored == scored, "scored is updated in modal.").fulfill()
def setUpClass(cls): cls.driver = webdriver.Firefox() time.sleep(11) cls.driver.maximize_window() cls.driver.get("http://www.iitm.ac.in/donlab/hts/") time.sleep(5) iSelect = Select(cls.driver.find_element_by_xpath(".//*[@id='AutoNumber1']/tbody/tr[1]/td[1]/select")) iSelect.select_by_value("kannadaf") time.sleep(2)
def amount_of_subjects(termnumber): driver.switch_to_frame(driver.find_element(By.XPATH,'//iframe[@name="TargetContent"]')) term = Select(driver.find_element(By.XPATH,'//div[@id="win0divCLASS_SRCH_WRK2_STRM$35$"]/select')) term.select_by_value(termnumber) time.sleep(10) select = Select(driver.find_element(By.XPATH,'//div[@id="win0divSSR_CLSRCH_WRK_SUBJECT_SRCH$0"]/select')) options = select.options driver.switch_to_default_content() return len(options)
def select_option_by_value(self, locator, value, index=0): """ Selects the option from locator whose value matches the given value. :param locator: :param value: :param index: """ select = Select(self._get_element(locator, index)) select.select_by_value(value)
def delete_experiment(self, experiment_name): self.driver.get(self.url+'/experiments/manage_main') end_time = time.time() + 60 while time.time() <= end_time: if self._check_exists_by_xpath("//option[@value='" + experiment_name + "']"): break self.driver.refresh() select = Select(self.driver.find_element_by_xpath("//select[@name='ids:list']")) select.select_by_value(experiment_name) self.driver.find_element_by_name("manage_delObjects:method").click()
def select_option_by_value_from_dropdown(self, element, value): self.wait_for_visible(element) element = self.find_element(element) select = Select(element) self._safe_log(u"Selecting by value '%s' from '%s'", value, self._to_string(element)) select.select_by_value(value)
def min_version(self, version=80): el = self.find_element(*self._min_version_select_locator) select = Select(el) select.select_by_value(f"FIREFOX_{version}")
def newApplicationFormOneStepTwo(self): windowBefore = self.driver.window_handles[0] print("Window Before=", windowBefore) self.wait.until( EC.element_to_be_clickable((By.XPATH, "//*[@name='firstName']"))) firstNameFill = self.driver.find_element(By.XPATH, "//*[@name='firstName']") firstNameFill.send_keys("Bharti") lastNameFill = self.driver.find_element(By.XPATH, "//*[@name='lastName']") lastNameFill.send_keys("Sharma") calendarFill = self.driver.find_element(By.XPATH, "//*[@name='dateOfBirth']") calendarFill.click() yearDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__year-select']") yearSel = Select(yearDropdown) yearSel.select_by_value('1983') monthDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__month-select']") monthSel = Select(monthDropdown) monthSel.select_by_value('0') dateSel = self.driver.find_element(By.XPATH, "//*[@aria-label='day-18']") dateSel.click() time.sleep(2) # houseNumberFill = self.driver.find_element( By.XPATH, "//*[@name='permanentHouseNo']") houseNumberFill.send_keys('12312') roadNumberFill = self.driver.find_element( By.XPATH, "//*[@name='permanentRoadNo']") roadNumberFill.send_keys('12312') countryFill = self.driver.find_element( By.XPATH, "//*[@name='permanentCountry']") countryFill.send_keys('India') time.sleep(1) countryToSel = self.driver.find_element(By.XPATH, "//*[contains(text(),'Ind')]") countryToSel.click() time.sleep(1) print("Country Filled") stateFill = self.driver.find_element(By.XPATH, "//*[@name='permanentState']") stateFill.send_keys('MAHA') time.sleep(1) stateToSel = self.driver.find_element(By.XPATH, "//*[contains(text(),'MAHA')]") stateToSel.click() time.sleep(1) print("State Filled") cityFill = self.driver.find_element(By.XPATH, "//*[@name='permanentCity']") cityFill.click() cityFill.send_keys('MUM') time.sleep(1) cityToSel = self.driver.find_element(By.XPATH, "//*[contains(text(),'MUM')]") cityToSel.click() time.sleep(1) print("City Filled") pinToFill = self.driver.find_element(By.XPATH, "//*[@name='permanentPinCode']") pinToFill.send_keys('400081') time.sleep(1) alternateNumberToFill = self.driver.find_element( By.XPATH, "//*[@name='alternateMobileNo']") alternateNumberToFill.send_keys('7977412402') print("Alternate number Filled") time.sleep(1) proofDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[2]") proofDropdown.click() time.sleep(2) self.wait.until( EC.element_to_be_clickable((By.XPATH, "//*[@id='liId_Voter ID']"))) proofSel = self.driver.find_element(By.XPATH, "//*[@id='liId_Voter ID']") proofSel.click() time.sleep(1) addProofEnter = self.driver.find_element(By.XPATH, "//*[@name= 'proofNumber']") addProofEnter.send_keys("123456789012") time.sleep(1) ##############Life Insured Details################333 lifeToInsured = self.driver.find_element(By.XPATH, "//*[@name= 'insurerName']") lifeToInsured.send_keys("Ram") time.sleep(1) lifegenderSelected = self.driver.find_element( By.XPATH, "(//*[contains(text(),'Female')])[2]") lifegenderSelected.click() print("Gender Clicked") time.sleep(1) lifecalendarFill = self.driver.find_element( By.XPATH, "//*[@name='insurerDateOfBirth']") lifecalendarFill.click() time.sleep(1) lifeyearDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__year-select']") yearSel = Select(lifeyearDropdown) yearSel.select_by_value('1988') lifemonthDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__month-select']") monthSel = Select(lifemonthDropdown) monthSel.select_by_value('0') dateSel = self.driver.find_element(By.XPATH, "//*[@aria-label='day-20']") dateSel.click() time.sleep(2) liferelationshipDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[4]") liferelationshipDropdown.click() time.sleep(1) optionInLifeRelationshipProposer = self.driver.find_element( By.XPATH, "//*[@id ='liId_Wife']") optionInLifeRelationshipProposer.click() print("Relationship Brother Selected.") time.sleep(1) #################################################33 purposeOfInsuranceDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[6]") purposeOfInsuranceDropdown.click() time.sleep(1) optionInInsuranceDropdown = self.driver.find_element( By.XPATH, "//*[contains(text(),'Retirement')]") optionInInsuranceDropdown.click() print("Retirement Selected") lifeStageDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[7]") lifeStageDropdown.click() optionInLifeStage = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Married with children')]") optionInLifeStage.click() print("Single Selected") grossIncomeFill = self.driver.find_element(By.XPATH, "//*[@name='income']") grossIncomeFill.send_keys('1200000') print("Gross Income Entered") existingPolicy = self.driver.find_element( By.XPATH, "(//*[contains(text(),'No')])[3]") existingPolicy.click() occupationDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[8]") occupationDropdown.click() optionInOccupation = self.driver.find_element( By.XPATH, "//*[@id='liId_Salaried']") optionInOccupation.click() print("Salaried Selected") time.sleep(2) recommendProduct = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[10]") recommendProduct.click() time.sleep(5) recommendProduct.click() time.sleep(1) self.wait.until( EC.element_to_be_clickable( (By.XPATH, "//*[@id='liId_Max Life Life Perfect Partner Super']"))) optionInRecommendProduct = self.driver.find_element( By.XPATH, "//*[@id='liId_Max Life Life Perfect Partner Super']") optionInRecommendProduct.click() print("Product Selected") premiumPaymentTerm = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[11]") premiumPaymentTerm.click() time.sleep(1) optionInPremiumPaymentTerm = self.driver.find_element( By.XPATH, "//*[@id='liId_7']") optionInPremiumPaymentTerm.click() print("Premium Payment Selected") time.sleep(2) policyTerm = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[12]") policyTerm.click() time.sleep(1) optionInPolicyTerm = self.driver.find_element(By.XPATH, "//*[@id='liId_43']") optionInPolicyTerm.click() print("Policy Term Selected") time.sleep(2) premiumCommitFill = self.driver.find_element( By.XPATH, "//*[@name='premiumCommitment']") premiumCommitFill.send_keys("200000") print("Sum Assured Filled") dividendDropdownSelected = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[14]") dividendDropdownSelected.click() print("Dividend dropdown Clicked") time.sleep(2) optionIndividendDropdownSelected = self.driver.find_element( By.XPATH, "//*[@id='liId_Cash']") optionIndividendDropdownSelected.click() print("Premium Offset selected") time.sleep(1) buttonProceedClick = self.driver.find_element( By.XPATH, "//*[contains(text(),'Proceed')]") buttonProceedClick.click() time.sleep(1) # self.wait.until(EC.element_to_be_clickable((By.XPATH, "(//*[@id='popupProceed'])[1]"))) # buttonYes= self.driver.find_element(By.XPATH, "(//*[@id='popupProceed'])[1]") # buttonYes.click() ########################### step 3 ############################# time.sleep(4) self.driver.switch_to_window(windowBefore) time.sleep(2) self.wait.until( EC.element_to_be_clickable((By.XPATH, "//*[@name='fatherName']"))) fatherNameFill = self.driver.find_element(By.XPATH, "//*[@name='fatherName']") fatherNameFill.send_keys("Ram") motherNameFill = self.driver.find_element(By.XPATH, "//*[@name='motherName']") motherNameFill.send_keys("Kumari") maritalStatus = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[2]") maritalStatus.click() time.sleep(1) optionInMaritalStage = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Married')]") optionInMaritalStage.click() print("Single Selected") educationSelect = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[3]") educationSelect.click() time.sleep(1) optionInEducationDropdown = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Post Graduate')][1]") optionInEducationDropdown.click() print("Education Selected") industrySelect = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[4]") industrySelect.click() time.sleep(1) optionInIndustrySelect = self.driver.find_element( By.XPATH, "//*[@id='liId_Defence']") optionInIndustrySelect.click() print("Industry Selected") time.sleep(1) organisationSelect = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[5]") organisationSelect.click() time.sleep(1) optionInOrganisationSelect = self.driver.find_element( By.XPATH, "//*[@id='liId_Pvt Ltd']") optionInOrganisationSelect.click() print("Organisation Selected") time.sleep(1) organisationFill = self.driver.find_element( By.XPATH, "//*[@name='companyName']") organisationFill.send_keys("ORG") preferredLanguage = self.driver.find_element( By.XPATH, "(//*[@ tabindex='0'])[7]") preferredLanguage.click() time.sleep(1) optionInPreferredLanguage = self.driver.find_element( By.XPATH, "//*[@id='liId_English']") optionInPreferredLanguage.click() print("Hindi Selected") time.sleep(1) # organisationFill = self.driver.find_element(By.XPATH, "//*[@name='nomineeName']") # organisationFill.send_keys("Nominee") # # calendarNomineeFill = self.driver.find_element(By.XPATH, "//*[@name='nomineeDateOfBirth']") # calendarNomineeFill.click() # # yearNomineeDropdown = self.driver.find_element(By.XPATH, "//*[@class='react-datepicker__year-select']") # yearNomineeSel = Select(yearNomineeDropdown) # yearNomineeSel.select_by_value('1994') # # monthNomineeDropdown = self.driver.find_element(By.XPATH, "//*[@class='react-datepicker__month-select']") # monthNomineeSel = Select(monthNomineeDropdown) # monthNomineeSel.select_by_value('3') # # dateNomineeSel = self.driver.find_element(By.XPATH, "//*[@aria-label='day-10']") # dateNomineeSel.click() # # genderSelected = self.driver.find_element(By.XPATH, "//*[contains(text(),'Male')]") # genderSelected.click() # print("Gender Clicked") # # relationshipProposer = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[8]") # relationshipProposer.click() # time.sleep(1) # optionInRelationshipProposer= self.driver.find_element(By.XPATH, "//*[@id ='liId_Brother']") # optionInRelationshipProposer.click() # print("Relationship Brother Selected.") bankFill = self.driver.find_element(By.XPATH, "//*[@name='bankAccountNo']") bankFill.send_keys("99999999999999") nameOfAccount = self.driver.find_element( By.XPATH, "//*[@name='bankAccountHolderName']") nameOfAccount.send_keys("NameName") nameOfIFSCcode = self.driver.find_element( By.XPATH, "//*[@name='bankAccountIFSC']") nameOfIFSCcode.send_keys("ICIC0001147") codeMICR = self.driver.find_element(By.XPATH, "//*[@name='bankAccountMICR']") codeMICR.send_keys("110229197") time.sleep(3) accountType = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[9]") accountType.click() time.sleep(2) accountTypeSelect = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Savings')]") accountTypeSelect.click() print("Account Type Selected.") time.sleep(2) ##################Life Insured Details fatherNameFill = self.driver.find_element( By.XPATH, "//*[@name='insurerFatherName']") fatherNameFill.send_keys("Chotu") dobDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[11]") dobDropdown.click() optiondobDropdown = self.driver.find_element( By.XPATH, "//*[@id='liId_Voter ID']") optiondobDropdown.click() time.sleep(1) educationdropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[12]") educationdropdown.click() optioneducationdropdownn = self.driver.find_element( By.XPATH, "//*[@id='liId_Graduate']") optioneducationdropdownn.click() time.sleep(1) maritalStatus = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[13]") maritalStatus.click() optionmaritalStatus = self.driver.find_element( By.XPATH, "//*[@id='liId_Married']") optionmaritalStatus.click() time.sleep(1) indsturyDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[14]") indsturyDropdown.click() time.sleep(1) optionindsturyDropdown = self.driver.find_element( By.XPATH, "//*[@id='liId_Defence']") optionindsturyDropdown.click() time.sleep(1) orgDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[15]") orgDropdown.click() time.sleep(1) optionorgDropdown = self.driver.find_element( By.XPATH, "//*[@id='liId_Pvt Ltd']") optionorgDropdown.click() time.sleep(1) occDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[17]") occDropdown.click() time.sleep(1) optionoccDropdown = self.driver.find_element( By.XPATH, "//*[@id='liId_Salaried']") optionoccDropdown.click() time.sleep(1) enterIncome = self.driver.find_element( By.XPATH, "//*[@name='insurerAnnualIncome']") enterIncome.send_keys("1000000") time.sleep(1) orgName = self.driver.find_element(By.XPATH, "//*[@name='insurerCompanyName']") orgName.send_keys("MAX") time.sleep(1) hazardous = self.driver.find_element( By.XPATH, "//*[@for='InsurerHazardousActivitiesNo']") hazardous.click() criminal = self.driver.find_element( By.XPATH, "//*[@for='InsurerCriminalChargesNo']") criminal.click() holiday = self.driver.find_element( By.XPATH, "//*[@for='insurerTravelOrResideAbroadNo']") holiday.click() heightInFeet = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[18]") heightInFeet.click() time.sleep(1) selectHeightInFeet = self.driver.find_element(By.XPATH, "//*[@id='liId_5']") selectHeightInFeet.click() time.sleep(1) heightInInches = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[19]") heightInInches.click() time.sleep(1) selectHeightInInches = self.driver.find_element( By.XPATH, "//*[@id='liId_5']") selectHeightInInches.click() time.sleep(1) weightFill = self.driver.find_element( By.XPATH, "//*[@name='insurerWeightInKgs']") weightFill.click() time.sleep(1) weightFill.send_keys("55") time.sleep(2) btnProceedOnPage4 = self.driver.find_element( By.XPATH, "//*[contains(text(),'Proceed')]") btnProceedOnPage4.click() print("Proceed Button Clicked.") time.sleep(1) #####################################3 btnProceedOnPage3 = self.driver.find_element( By.XPATH, "//*[contains(text(),'Proceed')]") btnProceedOnPage3.click() self.wait.until( EC.element_to_be_clickable((By.XPATH, "//*[@id='popupProceed']"))) verificationLinkPopUp = self.driver.find_element( By.XPATH, "//*[@id='popupProceed']") verificationLinkPopUp.click() print("Verification Link Sent.")
def testRegistratiom(self): signinButton = self.driver.find_element_by_class_name("login") signinButton.click() emailField = self.driver.find_element_by_id("email_create") emailField.send_keys(emailI) submitCreate = self.driver.find_element_by_id("SubmitCreate") submitCreate.click() genderButton = self.driver.find_element_by_id("id_gender2") genderButton.click() firstName = self.driver.find_element_by_id("customer_firstname") firstName.send_keys(firstNameI) lastName = self.driver.find_element_by_id("customer_lastname") lastName.send_keys(lastNameI) emailField2 = self.driver.find_element_by_id("email") emailValue = emailField2.get_attribute("value") assert emailValue == emailI passwordField = self.driver.find_element_by_id("passwd") passwordField.send_keys(password) days = Select(self.driver.find_element_by_id('days')) days.select_by_index(1) months = Select(self.driver.find_element_by_id('months')) months.select_by_index(3) years = Select(self.driver.find_element_by_id('years')) years.select_by_value('2000') specialOffers = self.driver.find_element_by_id("optin") specialOffers.click() # firstNameControl = self.driver.find_element_by_id("firstname") # firstNameControlValue = emailField2.get_attribute("value") address1 = self.driver.find_element_by_id("address1") address1.send_keys(addressOne) address2 = self.driver.find_element_by_id("address2") address2.send_keys(addressTwo) cityField = self.driver.find_element_by_id("city") cityField.send_keys(cityI) stateField = Select(self.driver.find_element_by_id('id_state')) stateField.select_by_value('5') zipCodeField = self.driver.find_element_by_id("postcode") zipCodeField.send_keys(zipCodeI) phoneMobileField = self.driver.find_element_by_id("phone_mobile") phoneMobileField.send_keys(phoneMobileI) addressAliasField = self.driver.find_element_by_id("alias") addressAliasField.clear() addressAliasField.send_keys(addressAliasI) submitButton = self.driver.find_element_by_id("submitAccount") submitButton.click() home = self.driver.find_element_by_class_name("navigation_page") assert home.text == 'My account' time.sleep(5) pass
def featurecode(): try: browser.get( 'https://{}/?menu=pbxconfig&type=setup&display=featurecodeadmin'. format(BASE_IP)) # 实例化 sel = Select( browser.find_element_by_name( 'ena#blacklist#blacklist_add')) # 实例化Select sel.select_by_visible_text('Disabled') se2 = Select( browser.find_element_by_name('ena#blacklist#blacklist_last')) se2.select_by_value('0') se3 = Select( browser.find_element_by_name( 'ena#blacklist#blacklist_remove')) # 实例化Select se3.select_by_visible_text('Disabled') se4 = Select(browser.find_element_by_name('ena#callforward#cfon')) se4.select_by_value('0') se5 = Select( browser.find_element_by_name('ena#callforward#cfoff')) # 实例化Select se5.select_by_visible_text('Disabled') se6 = Select(browser.find_element_by_name('ena#callforward#cfpon')) se6.select_by_value('0') se7 = Select(browser.find_element_by_name( 'ena#callforward#cfoff_any')) # 实例化Select se7.select_by_visible_text('Disabled') se8 = Select(browser.find_element_by_name('ena#callforward#cfbon')) se8.select_by_value('0') se9 = Select(browser.find_element_by_name( 'ena#callforward#cfboff')) # 实例化Select se9.select_by_visible_text('Disabled') se10 = Select(browser.find_element_by_name('ena#callforward#cfbpon')) se10.select_by_value('0') se11 = Select( browser.find_element_by_name( 'ena#callforward#cfboff_any')) # 实例化Select se11.select_by_visible_text('Disabled') se12 = Select(browser.find_element_by_name('ena#callforward#cfuon')) se12.select_by_value('0') se13 = Select(browser.find_element_by_name( 'ena#callforward#cfupon')) # 实例化Select se13.select_by_visible_text('Disabled') se14 = Select( browser.find_element_by_name('ena#callforward#cf_toggle')) se14.select_by_value('0') se15 = Select( browser.find_element_by_name('ena#callwaiting#cwon')) # 实例化Select se15.select_by_visible_text('Disabled') se16 = Select(browser.find_element_by_name('ena#callwaiting#cwoff')) se16.select_by_value('0') se17 = Select( browser.find_element_by_name( 'ena#timeconditions#toggle-mode-all')) # 实例化Select se17.select_by_visible_text('Disabled') se18 = Select( browser.find_element_by_name('ena#voicemail#dialvoicemail')) se18.select_by_value('0') se19 = Select( browser.find_element_by_name( 'ena#voicemail#directdialvoicemail')) # 实例化Select se19.select_by_visible_text('Disabled') se20 = Select( browser.find_element_by_name('ena#voicemail#myvoicemail')) se20.select_by_value('0') se21 = Select( browser.find_element_by_name('ena#infoservices#speakingclock')) se21.select_by_value('0') se22 = Select( browser.find_element_by_name( 'ena#recordings#record_check')) # 实例化Select se22.select_by_visible_text('Disabled') se23 = Select(browser.find_element_by_name('ena#queues#que_toggle')) se23.select_by_value('0') se24 = Select( browser.find_element_by_name( 'ena#queues#que_pause_toggle')) # 实例化Select se24.select_by_visible_text('Disabled') se25 = Select(browser.find_element_by_name('ena#queues#que_callers')) se25.select_by_value('0') # 保存 browser.find_element_by_css_selector( '#page_body > form > table > tbody > tr:nth-child(81) > td > h6 > input' ).click() except: pass
def testSelectExample2(self): SelectExample = self.driver.find_element_by_id( "multiple-select-example") sel = Select(SelectExample) sel.select_by_value("orange") time.sleep(1)
def test_hotel_booking(self): self.driver.implicitly_wait(15) log = self.getLogger() hotelHomePage = HotelHomePage(self.driver) hotelHomePage.get_go_hotel_page().click() hotelHomePage.get_field_destination().click() hotelHomePage.get_clear_text().clear() time.sleep(1) hotelHomePage.get_input_destination().send_keys("Bhopal") hotelHomePage.get_input_destination().send_keys(" Madhya Pradesh") time.sleep(2) log.info("Location is entered") hotelHomePage.get_field_destination().send_keys(Keys.ENTER) time.sleep(2) hotelHomePage.get_check_in_field().click() time.sleep(2) hotelHomePage.get_check_in_date().click() hotelHomePage.get_check_out_field().click() time.sleep(1) hotelHomePage.get_check_out_date().click() hotel_list_page = hotelHomePage.get_search_button() price_range = hotel_list_page.get_price_range_list() for new_range in price_range: if "Rs. 7,001 to Rs. 10,000" in new_range.text: new_range.click() break time.sleep(2) hotel_name_list = hotel_list_page.get_select_hotel_list() for names in hotel_name_list: hotel_name = names.find_element_by_xpath("div/div/h2").text if "Hotel Sarthak" in hotel_name: names.find_element_by_xpath("div[2]/div/span").click() # driver.find_element_by_tag_name("html").send_keys(Keys.END) ChildWindow = self.driver.window_handles[1] self.driver.switch_to.window(ChildWindow) time.sleep(2) hotel_list_page.get_view_more_button().click() room_types = hotel_list_page.get_room_types() for book in room_types: book_facility = book.find_element_by_xpath( "div/div[1]/span[1]").text if "Deluxe Single Room" in book_facility: book.find_element_by_xpath("div[2]/div[5]/button").click() break time.sleep(5) check_out_page = CheckOutPage(self.driver) check_out_page.get_hotel_input_email().send_keys("*****@*****.**") check_out_page.get_hotel_input_mobile().send_keys("9870466369") handlel_dropdown = Select(check_out_page.get_hotel_select_dropdown()) handlel_dropdown.select_by_value("Mr") check_out_page.get_hotel_input_firstname().send_keys("Neeraj Kumar") check_out_page.get_hotel_input_lastname().send_keys("Singh") time.sleep(5) paymentGateway = check_out_page.get_proceed_to_payment_button() time.sleep(1) paymentGateway.getAmazonPayment().click() paymentGateway.getAmazonPayment().click()
def dd_by_value(self, e, value): s = Select(e) s.select_by_value(value)
driver = webdriver.Chrome() driver.get('https://www.baidu.com/') driver.implicitly_wait(5) # 定位设置元素 set_ele = driver.find_element_by_xpath("//div[@id='u1']//a[text()='设置']") # 三行代码写成一行:支持链式调用 ActionChains(driver).move_to_element(set_ele).perform() # 等待高级设置可点击 WebDriverWait(driver, 5, 0.2).until( EC.element_to_be_clickable((By.XPATH, "//a[text()='高级搜索']"))).click() # ---------------下拉选择框的选择----------------------- select_ele = driver.find_element_by_xpath("//select[@name='gpc']") select = Select(select_ele) time.sleep(1) # 方式一:通过索引进行选择 # select.select_by_index(3) # 方式二:通过文本进行选择 # select.select_by_visible_text('最近一年') # 方式三:通过value进行选择 s2 = Select(driver.find_element_by_xpath("//select[@name='ft']")) s2.select_by_value('doc') time.sleep(20) driver.quit()
# 对定位的元素封装成Select类型对象 mycity =Select(city) mynation = Select(nation) sleep(1) # 使用索引设置选项 mycity.select_by_index(0) # 对城市进行操作 if mycity.is_multiple==True: print("城市可以多选") else: print("城市只能单选") sleep(1) mycity.select_by_value("重庆") sleep(1) mycity.select_by_visible_text("上海") print("所有的城市选项:") for i in mycity.options: print(i) print(i.text) for j in mycity.all_selected_options: print("目前选中的城市:",j.text) print("===========================") # 是否多选 if mynation.is_multiple ==True: print("民族可以多选") else:
def newApplicationFormOneStepThree(self): time.sleep(5) self.wait.until( EC.element_to_be_clickable((By.XPATH, "//*[@name='fatherName']"))) fatherNameFill = self.driver.find_element(By.XPATH, "//*[@name='fatherName']") fatherNameFill.send_keys("Father") motherNameFill = self.driver.find_element(By.XPATH, "//*[@name='motherName']") motherNameFill.send_keys("Mother") maritalStatus = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[2]") maritalStatus.click() time.sleep(1) optionInMaritalStage = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Married')]") optionInMaritalStage.click() print("Single Selected") educationSelect = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[3]") educationSelect.click() time.sleep(1) optionInEducationDropdown = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Professional')][1]") optionInEducationDropdown.click() print("Education Selected") industrySelect = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[4]") industrySelect.click() time.sleep(1) optionInIndustrySelect = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Merchant')][1]") optionInIndustrySelect.click() print("Industry Selected") organisationSelect = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[5]") organisationSelect.click() time.sleep(1) optionInOrganisationSelect = self.driver.find_element( By.XPATH, "//*[@id='liId_Govt']") optionInOrganisationSelect.click() print("Organisation Selected") natureSelect = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[6]") natureSelect.click() time.sleep(1) optionInNatureSelect = self.driver.find_element( By.XPATH, "//*[@id='liId_Cargo Vessel']") optionInNatureSelect.click() print("Nature Selected") organisationFill = self.driver.find_element( By.XPATH, "//*[@name='companyName']") organisationFill.send_keys("ORG") preferredLanguage = self.driver.find_element( By.XPATH, "(//*[@ tabindex='0'])[7]") preferredLanguage.click() time.sleep(1) optionInPreferredLanguage = self.driver.find_element( By.XPATH, "//*[@id='liId_Hindi']") optionInPreferredLanguage.click() print("Hindi Selected") time.sleep(2) organisationFill = self.driver.find_element( By.XPATH, "//*[@name='nomineeName']") organisationFill.send_keys("Nominee") calendarNomineeFill = self.driver.find_element( By.XPATH, "//*[@name='nomineeDateOfBirth']") calendarNomineeFill.click() yearNomineeDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__year-select']") yearNomineeSel = Select(yearNomineeDropdown) yearNomineeSel.select_by_value('1985') monthNomineeDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__month-select']") monthNomineeSel = Select(monthNomineeDropdown) monthNomineeSel.select_by_value('3') dateNomineeSel = self.driver.find_element(By.XPATH, "//*[@aria-label='day-10']") dateNomineeSel.click() genderSelected = self.driver.find_element( By.XPATH, "//*[contains(text(),'Male')]") genderSelected.click() print("Gender Clicked") relationshipProposer = self.driver.find_element( By.XPATH, "(//*[@ tabindex='0'])[9]") relationshipProposer.click() time.sleep(1) optionInRelationshipProposer = self.driver.find_element( By.XPATH, "//*[@id ='liId_Brother']") optionInRelationshipProposer.click() print("Relationship Brother Selected.") bankFill = self.driver.find_element(By.XPATH, "//*[@name='bankAccountNo']") bankFill.send_keys("99999999999999") nameOfAccount = self.driver.find_element( By.XPATH, "//*[@name='bankAccountHolderName']") nameOfAccount.send_keys("NameName") nameOfIFSCcode = self.driver.find_element( By.XPATH, "//*[@name='bankAccountIFSC']") nameOfIFSCcode.send_keys("SBIN0000845") codeMICR = self.driver.find_element(By.XPATH, "//*[@name='bankAccountMICR']") codeMICR.send_keys("515002206") time.sleep(3) accountType = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[11]") accountType.click() time.sleep(2) accountTypeSelect = self.driver.find_element( By.XPATH, "//*[contains(text(), 'Savings')]") accountTypeSelect.click() print("Account Type Selected.") time.sleep(2) calBankAcOpening = self.driver.find_element( By.XPATH, "//*[@name='bankAccOpeningDate']") calBankAcOpening.click() calDateSelect = self.driver.find_element(By.XPATH, "//*[@aria-label='day-3']") calDateSelect.click() btnProceedOnPage3 = self.driver.find_element( By.XPATH, "//*[contains(text(),'Proceed')]") btnProceedOnPage3.click() time.sleep(5)
def select_country(self, country): element = self.selenium.find_element(*self._country_locator) select = Select(element) select.select_by_value(country)
# s3=Select(year) # s3.select_by_index("2") # # driver.find_element_by_name("websubmit").click() from selenium.webdriver.support.select import Select browser = 'chrome' if (browser == 'chrome'): driver = webdriver.Chrome() elif (browser == 'ff'): driver = webdriver.Firefox() elif (browser == 'ie'): driver = webdriver.Ie() driver.get("https://jqueryui.com/datepicker/#dropdown-month-year") driver.implicitly_wait(30) #driver.find_element_by_id("datepicker").click() framevar = driver.find_element_by_xpath("//iframe[@class='demo-frame']") driver.switch_to_frame(framevar) driver.find_element_by_xpath("//input[@class='hasDatepicker']").click() month = driver.find_element_by_class_name("ui-datepicker-month") s1 = Select(month) s1.select_by_visible_text("Mar") year = driver.find_element_by_class_name("ui-datepicker-year") s2 = Select(year) s2.select_by_value("2010") driver.find_element_by_xpath("//a[text()='3']").click() #Assignment>> 1) Perform Select operation 2)Explain all exceptions 3)challen #4) Webelemet 5)Multiple select
def authModal(self, nombre, apellido, correo, area, rol, usuario, contraseña, check): try: driver = self.checkInfo( modulo= "http://ec2-34-210-56-229.us-west-2.compute.amazonaws.com:3001/#/administracion/:modulo", datos=[ "Nombre", "Apellidos", "Tipo", "Email", "Área", "Usuario", "Estatus" ]) if driver == None: print( "ocurrio un problema el driver no se retorno, proceso finalizado" ) return except: print("Error inesperado en el driver:", sys.exc_info()[0]) try: driver.quit() except: pass return su = SingUp() driver.find_element(By.XPATH, "//button[text()='Agregar usuario']").click() time.sleep(1) try: modal = driver.find_element( By.XPATH, "//div[@class='modal-dialog']//div[@class='modal-content']") except: print("element modal not found") su.takescreenshot(driver, namescren="FailModal", directory="TestModuleAdmin/") driver.quit() return try: modal.find_element(By.XPATH, "//div[@class='modal-header']") modal.find_element(By.XPATH, "//div[@class='modal-body']") modal.find_element(By.XPATH, "//div[@class='modal-footer']") except: su.takescreenshot(driver, namescren="FailModal", directory="TestModuleAdmin/") print("El modal no contiene una estructura valida") driver.quit() return try: su.takescreenshot(driver, namescren="Modal", directory="TestModuleAdmin/") driver.find_element(By.XPATH, "//input[@name='nombre']").send_keys(nombre) driver.find_element( By.XPATH, "//input[@name='apellido']").send_keys(apellido) driver.find_element(By.XPATH, "//input[@name='correo']").send_keys(correo) driver.find_element(By.XPATH, "//input[@name='area']").send_keys(area) sel = Select(driver.find_element(By.XPATH, "//select[@name='rol']")) #select sel.select_by_value(rol) driver.find_element(By.XPATH, "//input[@name='usuario']").send_keys(usuario) driver.find_element( By.XPATH, "//input[@type='password']").send_keys(contraseña) if check: checking = driver.find_element(By.XPATH, "//input[@name='activo']") driver.execute_script("arguments[0].click();", checking) su.takescreenshot(driver, namescren="CamposLlenos", directory="TestModuleAdmin/") driver.find_element(By.XPATH, "//input[@type='submit']").click() except: print("Error inesperado al registrar usuario :", sys.exc_info()[0]) driver.quit() return hw = HandyWrappers(driver) if hw.elementPresenceCheck( locator="//*[text()='¡El usuario ya existe!']", byType="xpath"): res = self.VerificarusrBD(usuario) if res > 0: print("Usuario existente, denegado con exito") else: print("El sistema denego un usuario valido") su.takescreenshot(driver, namescren="UsuarioExiste", directory="TestModuleAdmin/") driver.find_element( By.XPATH, "//button[contains(text(),'Aceptar')]").click() self.closeSshandConection() if not self.encuentraUsrFront(driver, 6, usuario): print( "El usuario denegado no se muestra en el front(esto no es correcto)" ) driver.quit() return su.takescreenshot(driver, namescren="UsuarioAgregado", directory="TestModuleAdmin/") driver.find_element(By.XPATH, "//button[contains(text(),'Aceptar')]").click() last = driver.find_element(By.XPATH, "//img[@src='./assets/img/last.png']") driver.execute_script("arguments[0].click();", last) res = self.VerificarusrBD(usuario) if res > 0: print("Usuario agregado correctamente a la BD") else: print("Ocurrio un problema al encontrar el usuario en la BD") driver.quit() return find_td = TD_VALIDAR.format(usuario) find = hw.getElement(locator=find_td, locatorType="XPATH") if not find: print("La pagina NO muestra correctamente el usuario") driver.quit() return down = driver.find_element(By.XPATH, "//img[contains(@src,'sort-down.png')]") driver.execute_script("arguments[0].click();", down) closesession = driver.find_element( By.XPATH, "// button[contains(text(), 'Cerrar sesión')]") driver.execute_script("arguments[0].click();", closesession) self.closeSshandConection() su.Login(driver=driver, user=usuario, passwd=contraseña, element={ "locator": "XPATH", "valueL": "//input[@type='text']" })
# 4 - Добавьте тест, что в селекторе выбран вариант сортировки от большего к меньшему # Используйте проверку по value element = driver.find_element_by_css_selector('[selected="selected"]') E_txt = element.text if E_txt == "Sort by price: high to low": print("4 - В селекторе выбрана сортировка: \"high to low\" - +") else: print("4 - В селекторе выбрана сортировка: " + "\"" + E_txt + "\" !!!") # 5 - Отсортируйте товары от большего к меньшему # в селекторах используйте класс Select S_Pr_desc = driver.find_element_by_css_selector('[name="orderby"]') select = Select(S_Pr_desc) select.select_by_value("price-desc") print("5 - Выбран метод сортировки: \"high to low\" - +") # 6 - Снова объявите переменную с локатором основного селектора сортировки # т.к после сортировки страница обновится element = driver.find_element_by_css_selector('[selected="selected"]') print("6 - Обьявлена переменнуя с локатором основного селектора сортировки - +") # 7 - Добавьте тест, что в селекторе выбран вариант сортировки от большего к меньшему # Используйте проверку по value E_txt = element.text if E_txt == "Sort by price: high to low": print("7 - В селекторе выбрана сортировка: \"high to low\" - +") else: print("7 - В селекторе выбрана сортировка: " + "\"" + E_txt + "\" !!!")
def newApplicationFormOneStepTwo(self): windowBefore = self.driver.window_handles[0] self.wait.until( EC.element_to_be_clickable( (By.XPATH, "//*[@name='alternateMobileNo']"))) alternateMobileNumber = self.driver.find_element( By.XPATH, "//*[@name='alternateMobileNo']") alternateMobileNumber.send_keys("9650479781") stdCode = self.driver.find_element(By.XPATH, "//*[@name='stdCode']") stdCode.send_keys("011") purposeOfInsuranceDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[3]") purposeOfInsuranceDropdown.click() optionInInsuranceDropdown = self.driver.find_element( By.XPATH, "//*[@id='liId_Wealth accumulation/Investment']") optionInInsuranceDropdown.click() print("Retirement Selected") lifeStageDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[4]") lifeStageDropdown.click() optionInLifeStage = self.driver.find_element( By.XPATH, "//*[@id='liId_Married with children']") optionInLifeStage.click() print("Single Selected") grossIncomeFill = self.driver.find_element(By.XPATH, "//*[@name='income']") grossIncomeFill.send_keys('1100000') print("Gross Income Entered") existingPolicy = self.driver.find_element( By.XPATH, "(//*[contains(text(),'No')])[4]") existingPolicy.click() occupationDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[5]") occupationDropdown.click() optionInOccupation = self.driver.find_element( By.XPATH, "//*[@id='liId_Salaried']") optionInOccupation.click() print("Salaried Selected") time.sleep(2) recommendProduct = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[7]") recommendProduct.click() time.sleep(10) recommendProduct.click() time.sleep(1) optionInRecommendProduct = self.driver.find_element( By.XPATH, "//*[@id='liId_Select Another Product']") optionInRecommendProduct.click() print("Product Selected") time.sleep(1) recommendProductName = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[8]") recommendProductName.click() time.sleep(1) optionInRecommendProductName = self.driver.find_element( By.XPATH, "//*[@id='liId_Max Life Shiksha Plus Super']") optionInRecommendProductName.click() print("Product Selected") premiumTypeDropdown = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[9]") premiumTypeDropdown.click() time.sleep(1) premiumTypeOption = self.driver.find_element(By.XPATH, "//*[@id='liId_15']") premiumTypeOption.click() print("Premium Type Selected") policyTerm = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[10]") policyTerm.click() time.sleep(1) policyTermValue = self.driver.find_element(By.XPATH, "//*[@id='liId_15']") policyTermValue.click() print("15 Selected") modeOfPayment = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[11]") modeOfPayment.click() time.sleep(1) modeOfPaymentValue = self.driver.find_element( By.XPATH, "//*[@id='liId_Annual']") modeOfPaymentValue.click() print("Annual Selected") optionInPaymentMode = self.driver.find_element( By.XPATH, "//*[@id='liId_Annual']") optionInPaymentMode.click() childCalendarFill = self.driver.find_element(By.XPATH, "//*[@name='childDob']") childCalendarFill.click() childMonthDropdown = self.driver.find_element( By.XPATH, "//*[@class='react-datepicker__month-select']") childMonthSel = Select(childMonthDropdown) childMonthSel.select_by_value('9') childDateSel = self.driver.find_element(By.XPATH, "//*[@aria-label='day-31']") childDateSel.click() premiumCommitFill = self.driver.find_element( By.XPATH, "//*[@name='premiumCommitment']") premiumCommitFill.send_keys("200000") print("Sum Assured Filled") chooseFund = self.driver.find_element(By.XPATH, "//*[@for='chooseFundNo']") chooseFund.click() chooseFund = self.driver.find_element(By.XPATH, "//*[@for='dynamicFundNo']") chooseFund.click() systematicFund = self.driver.find_element(By.XPATH, "//*[@for='systematicYes']") systematicFund.click() investorDropdownSelected = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[13]") investorDropdownSelected.click() print("Investor dropdown Clicked") time.sleep(2) optionInvestorDropdownSelected = self.driver.find_element( By.XPATH, "//*[@id='liId_I am comfortable taking on a higher level of risk, knowing it may mean higher returns.']" ) optionInvestorDropdownSelected.click() print("Investor dropdown Selected") time.sleep(2) investmentDropdownSelected = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[14]") investmentDropdownSelected.click() print("Investment dropdown Clicked") optionInvestmentDropdownSelected = self.driver.find_element( By.XPATH, "//*[@id='liId_Portfolio 1 : Equity - 100%- Debt- 0%']") optionInvestmentDropdownSelected.click() print("Investment Selected") investmentDropdownUp = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[15]") investmentDropdownUp.click() print("Investment dropdown Clicked") optionInvestmentDropdownUp = self.driver.find_element( By.XPATH, "//*[@id='liId_30%']") optionInvestmentDropdownUp.click() print("Investment Up Selected") habitDescription = self.driver.find_element( By.XPATH, "(//*[@tabindex='0'])[16]") habitDescription.click() print("Habit dropdown Clicked") time.sleep(1) optionHabitDescription = self.driver.find_element( By.XPATH, "//*[@id='liId_I am able to save substantial amount regularly, after covering living expenses.']" ) optionHabitDescription.click() print("Habit Selected") time.sleep(1) buttonProceedClick = self.driver.find_element( By.XPATH, "//*[contains(text(),'Proceed')]") buttonProceedClick.click() time.sleep(1) popUp = self.driver.find_element(By.XPATH, "(//*[contains(text(),'Yes')])[6]") popUp.click() time.sleep(8) self.driver.switch_to_window(windowBefore)
driver = webdriver.Chrome( executable_path="D:\SeleniumProject\Web_drivers\chromedriver") driver.maximize_window() driver.get("https://www.facebook.com/") driver.find_element_by_xpath( "/html/body/div[1]/div[2]/div[1]/div/div/div/div[2]/div/div[1]/form/div[5]" ).click() driver.implicitly_wait(5) element = driver.find_element_by_id("day") drp = Select(element) # Selection of value by visible text drp.select_by_visible_text("29") element2 = driver.find_element_by_id("month") drp2 = Select(element2) drp2.select_by_visible_text("Apr") # Select by index drp.select_by_index("9") # Select by value drp2.select_by_value("4") time.sleep(5) # Capture all the options from the drop down and print all_options = drp2.options for option in all_options: print(option.text) # Count number of options with in a drop down #print(len(drp2.options)) driver.quit()
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.select import Select import time driver = webdriver.Chrome() driver.maximize_window() driver.get("http://airindia.com") dropDown = driver.find_element(By.ID, "ContentPlaceHolder1_UserLanguage1_drpCountry") listBox = Select(dropDown) listBox.select_by_value("76") time.sleep(5) driver.close()
#browser = webdriver.Firefox() browser.implicitly_wait(30) # 隐性等待,最长等30秒 browser.get("http://betastore.carloudy.com") browser.maximize_window() browser.find_element_by_name("username").send_keys("junqianniub") browser.find_element_by_name("password").send_keys("1019042603QJ") time.sleep(2) browser.find_element_by_xpath("//button[text()='Log in']").click() print("Test1 --- Log in Successfully") print("*" * 50) time.sleep(2) system_type = Select( browser.find_element_by_xpath("/html//select[@id='inputState']")) system_type.select_by_value("iOS") # system_type.select_by_value("Android") #file_path_ios = r'C:/Users\qianj\Desktop\1.png' file_path_ios = os.path.realpath( 'WebTest/image/1.png' ) #link for OS 操作: https://blog.csdn.net/xiongchengluo1129/article/details/79181246 #print(file_path_ios) browser.find_element_by_name("RegisterAppName").send_keys("Test iOS 1") time.sleep(2) uploade_icon_ios_path = browser.find_element_by_xpath( "/html//input[@id='exampleFormControlFile2']") time.sleep(2) uploade_icon_ios_path.send_keys(file_path_ios) time.sleep(2) browser.find_element_by_name("RegisterPackageName").send_keys( "Test iOS Package Name 1")
table_list=[] with open(csv_file_name, 'w', encoding='utf-8-sig', newline='') as f: w = csv.writer(f) w.writerow(column_list) # 컬럼 설정 # 중분류에 따라 반복문 실행 for value in selIndus_list: # chromedriver로 브라우저 실행(정보공개서 브랜드별) browser = webdriver.Chrome('/Users/SAMSUNG/chromedriver_win32/chromedriver') browser.get('https://franchise.ftc.go.kr/user/extra/main/221/firHope/listHq/jsp/LayOutPage.do') # 업종 대분류 설정(21=외식, 22=도소매, 23=서비스) selUpjong = Select(browser.find_element_by_id('selUpjong')) selUpjong.select_by_value(selUpjong_value) time.sleep(1) # 업종 중분류 설정 selIndus = Select(browser.find_element_by_id('selIndus')) selIndus.select_by_value(value) time.sleep(1) # 비교 항목('listBrand01','listBrand02','listBrand03') (브랜드개요, 현황정보, 창업비용) selListType = Select(browser.find_element_by_id('selListType')) selListType.select_by_value(item) time.sleep(1) # 검색버튼 클릭 browser.find_element_by_xpath('//*[@id="frmSearch"]/input[5]').click() time.sleep(1)
def bind_iban(self): """ 绑定Iban :return: """ self.driver.get( url='https://eu.battle.net/login/de/?ref=https://eu.battle.net/account/management/add-payment-method.html&app=bam&cr=true') # 输入用户名密码 emil = self.driver.find_element_by_id('accountName') emil.send_keys(self.username) passwird = self.driver.find_element_by_id('password') passwird.send_keys(self.password) if emil.get_attribute('value') == self.username and passwird.get_attribute('value') == self.password: print('输入成功') else: print('输入失败,重新输入') self.driver.execute_script("""$("input[name='accountName']").val('%s')""" % self.username) self.driver.execute_script("""$("input[name='password']").val('%s')""" % self.username) time.sleep(0.5) try: submit_btn = self.driver.find_element_by_id('submit') submit_btn.click() except Exception: self.driver.execute_script("$('#submit').click()") time.sleep(2) if self.driver.current_url == 'https://eu.battle.net/account/management/add-payment-method.html': try: selector = Select(self.driver.find_element_by_id('paymentMethod')) print(selector) selector.select_by_value('ELV') except Exception: self.driver.execute_script("$('#paymentMethod').val('ELV')") # 输入内容 bank_name = self.driver.find_element_by_id('accountHolderName') bank_name.send_keys('a') iban_input = self.driver.find_element_by_id('iban') iban_input.send_keys(self.IBAN) first_name_input = self.driver.find_element_by_id('address.firstname') first_name_input.send_keys('a') last_name_input = self.driver.find_element_by_id('address.lastname') last_name_input.send_keys('a') address_input = self.driver.find_element_by_id('address.address1') address_input.send_keys('a') city_input = self.driver.find_element_by_id('address.city') city_input.send_keys('a') zipcode_input = self.driver.find_element_by_id('address.zipcode') zipcode_input.send_keys('12345') submit_save_iban_btn = self.driver.find_element_by_id('creation-submit') submit_save_iban_btn.click() if self.driver.current_url == 'https://eu.battle.net/account/management/add-payment-method.html': if self.driver.page_source.find('SEPA Direct Debit Mandate') != -1 or self.driver.page_source.find( 'SEPA-Lastschrift-Mandat') != -1: submit_save_iban_btn = self.driver.find_element_by_id('creation-submit') submit_save_iban_btn.click() time.sleep(2) print(self.driver.current_url) if self.driver.current_url == 'https://eu.battle.net/account/management/add-payment-method.html?mandateConfirm=true': if self.driver.page_source.find( 'Zahlungsmethode hinzugefügt') != -1 or self.driver.page_source.find('已新增付費方式'): return self.username, self.password, self.IBAN
def set_select_by_CLASS(self, class_name, value): box = WebDriverWait(self.driver, 30).until( EC.presence_of_element_located((By.CLASS_NAME, class_name))) option = Select(box) option.select_by_value(value)
def test_diffs(self): self.driver.get('http://*****:*****@id="timeline"]/div[2]/ul/li[1]/div/div/div/form/select')) # select version to compare to diff_field.select_by_value('2012-12121') # wait until diff view has loaded w/ JS WebDriverWait(self.driver, 30).until( lambda driver: driver.find_element_by_css_selector('html.js')) WebDriverWait(self.driver, 60) # make sure the url is right self.assertTrue( self.driver.current_url == 'http://*****:*****@id="toc"]/ol/li[3]') # drawer should have green bar self.assertTrue('modified' in toc_link_1005_3.get_attribute('class')) toc_link_1005_3.click() # wait until 1005.3 diff loads WebDriverWait(self.driver, 30).until( lambda driver: driver.current_url == 'http://*****:*****@id="1005-3-b-1-vi"]') self.assertTrue(new_section.find_element_by_tag_name('ins')) # make sure changed paragraph has insertions and deletions changed_section = self.driver.find_element_by_xpath( '//*[@id="1005-3-b-2-ii"]') self.assertTrue( len(changed_section.find_elements_by_tag_name('ins')) == 2) self.assertTrue(len(changed_section.find_elements_by_tag_name('del'))) # go back into diff pane in drawer, stop comparing self.get_drawer_button().click() stop_button = self.driver.find_element_by_xpath( '//*[@id="timeline"]/div[2]/ul/li[2]/div/a') stop_button.click() # make sure it goes back to the right place WebDriverWait(self.driver, 30).until(lambda driver: driver.current_url == 'http://localhost:8000/1005-3/2011-11111')
driver.find_element_by_name("address[address_name]").send_keys("张三") driver.find_element_by_name("address[mobile]").send_keys("1512345678") #下拉框是一张特殊的网页元素,对下拉框的操作和普通网页元素 dropdown1 = driver.find_element_by_id("add-new-area-select") #下拉框是一张特殊的网页元素,对下拉框的操作和普通网页元素 #selenium为这种特殊元素,专门创建了一个类Select #dropdown1的类型是一个普通的页面元素,下面这句代码的意思是,把一个普通的网页类型,转换成一个下拉框的特殊网页元素 print(type(dropdown1)) #dropdown1是Web_element类型 #Web_element这个类中,只有click和send_keys这样的方法,没有选择下拉框选项的方法 select1 = Select(dropdown1) print(type(select1)) #select1是Selcet #转换成select类型之后,网页元素还是那个元素,但是Select类中有选择项的方法 select1.select_by_value("320000") #这时,我们可以通过选项值来定位 time.sleep(2) select1.select_by_visible_text("辽宁省") #也可以通过选项的文本信息来定位 #可以用find_elements的方法,先找页面上所有的 #下标的方式选择第N个页面元素 dropdown2 = driver.find_elements_by_class_name("add-new-area-select")[1] Select(dropdown2).select_by_visible_text("沈阳市") #dropdown3 = driver.find_elements_by_class_name("add-new-area-select")[2] #等同于下面这句 #tag_name()这个方法,大多数情况都能找到一对元素,所以find_element_tag_name()这个方法很少用 #但是find_elements_tag_name()[n]这个方法 dropdown3 = driver.find_elements_by_tag_name("select")[2] Select(dropdown3).select_by_visible_text("铁西区")
def newApplicationFormOneStepTwo(self): windowBefore = self.driver.window_handles[0] print("Window Before=",windowBefore) self.wait.until(EC.element_to_be_clickable((By.XPATH,"//*[@name='firstName']"))) firstNameFill = self.driver.find_element(By.XPATH,"//*[@name='firstName']") firstNameFill.send_keys("Atul") lastNameFill = self.driver.find_element(By.XPATH,"//*[@name='lastName']") lastNameFill.send_keys("Joshina") calendarFill= self.driver.find_element(By.XPATH,"//*[@name='dateOfBirth']") calendarFill.click() yearDropdown = self.driver.find_element(By.XPATH,"//*[@class='react-datepicker__year-select']") yearSel = Select(yearDropdown) yearSel.select_by_value('1962') monthDropdown = self.driver.find_element(By.XPATH,"//*[@class='react-datepicker__month-select']") monthSel= Select(monthDropdown) monthSel.select_by_value('11') dateSel=self.driver.find_element(By.XPATH,"//*[@aria-label='day-8']") dateSel.click() proofDropdown= self.driver.find_element(By.XPATH, "(//*[@aria-pressed='false'])[1]") proofDropdown.click() time.sleep(8) self.wait.until(EC.element_to_be_clickable((By.XPATH, "(// *[contains(text(), 'Driving')])[1]"))) proofSel = self.driver.find_element(By.XPATH, "(// *[contains(text(), 'Driving')])[1]") proofSel.click() time.sleep(2) houseNumberFill= self.driver.find_element(By.XPATH,"//*[@name='permanentHouseNo']") houseNumberFill.send_keys('12312') roadNumberFill = self.driver.find_element(By.XPATH, "//*[@name='permanentRoadNo']") roadNumberFill.send_keys('12312') time.sleep(1) # countryFill = self.driver.find_element(By.XPATH, "//*[@name='permanentCountry']") # countryFill.send_keys('IND') # time.sleep(1) # countryToSel = self.driver.find_element(By.XPATH, "//*[contains(text(),'Ind')]") # countryToSel.click() # time.sleep(1) # print("Country Filled") # stateFill = self.driver.find_element(By.XPATH, "//*[@name='permanentState']") # stateFill.send_keys('Har') # time.sleep(1) # stateToSel=self.driver.find_element(By.XPATH, "//*[contains(text(),'HAR')]") # stateToSel.click() # time.sleep(1) # print("State Filled") # # cityFill = self.driver.find_element(By.XPATH, "//*[@name='permanentCity']") # cityFill.click() # cityFill.send_keys('GUR') # time.sleep(1) # cityToSel= self.driver.find_element(By.XPATH, "//*[contains(text(),'GU')]") # cityToSel.click() # time.sleep(1) # print("City Filled") # # pinToFill= self.driver.find_element(By.XPATH, "//*[@name='permanentPinCode']") # pinToFill.send_keys('122010') # time.sleep(1) alternateNumberToFill = self.driver.find_element(By.XPATH, "//*[@name='alternateMobileNo']") alternateNumberToFill.send_keys('9650479781') print("Alternate number Filled") purposeOfInsuranceDropdown= self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[4]") purposeOfInsuranceDropdown.click() optionInInsuranceDropdown=self.driver.find_element(By.XPATH,"//*[@id='liId_Retirement']") optionInInsuranceDropdown.click() print("Retirement Selected") lifeStageDropdown= self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[5]") lifeStageDropdown.click() optionInLifeStage= self.driver.find_element(By.XPATH, "//*[@id='liId_Married with children']") optionInLifeStage.click() print("Single Selected") # grossIncomeFill = self.driver.find_element(By.XPATH, "//*[@name='income']") # grossIncomeFill.send_keys('500000') # print("Gross Income Entered") # time.sleep(1) existingPolicy=self.driver.find_element(By.XPATH, "(//*[contains(text(),'No')])[4]") existingPolicy.click() time.sleep(1) occupationDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[6]") occupationDropdown.click() time.sleep(1) optionInOccupation = self.driver.find_element(By.XPATH, "//*[@id='liId_Salaried']") optionInOccupation.click() print("Salaried Selected") time.sleep(1) recommendProduct= self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[8]") recommendProduct.click() time.sleep(5) recommendProduct.click() time.sleep(1) optionInRecommendProduct = self.driver.find_element(By.XPATH, "//*[@id='liId_Forever Young Pension Plan']") optionInRecommendProduct.click() print("Product Selected") # vestingDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[10]") # vestingDropdown.click() # vestingOption = self.driver.find_element(By.XPATH, "//*[@id='liId_75']") # vestingOption.click() # print("Vesting Selected") premiumTypeDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[15]") premiumTypeDropdown.click() premiumTypeOption = self.driver.find_element(By.XPATH, "//*[@id='liId_Single Pay']") premiumTypeOption.click() print("Premium Type Selected") # coverMultipeDropdown = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[11]") # coverMultipeDropdown.click() # coverMultipeDropdownOption = self.driver.find_element(By.XPATH, "//*[@id='liId_10']") # coverMultipeDropdownOption.click() # print("10 Selected") # premiumPaymentTerm = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[12]") # premiumPaymentTerm.click() # time.sleep(1) # optionInPremiumPaymentTerm = self.driver.find_element(By.XPATH, "//*[@id='liId_1']") # optionInPremiumPaymentTerm.click() # print("Premium Payment Selected") # time.sleep(2) # # policyTerm = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[13]") # policyTerm.click() # time.sleep(2) # optionPolicyTerm = self.driver.find_element(By.XPATH, "//*[@id='liId_35']") # optionPolicyTerm.click() # print("Policy Term Selected") # time.sleep(1) saveMore = self. driver.find_element(By.XPATH, "//*[@for='saveMoreTomorrowNo']") saveMore.click() fundOption = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[14]") fundOption.click() time.sleep(2) optionFundOption = self.driver.find_element(By.XPATH, "//*[@id='liId_Pension Preserver Option']") optionFundOption.click() print("Policy Term Selected") time.sleep(1) modeOfPayment = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[15]") modeOfPayment.click() time.sleep(1) modeOfPaymentOption = self.driver.find_element(By.XPATH, "//*[@id='liId_Single']") modeOfPaymentOption.click() print("Mode Selected") time.sleep(1) premiumCommitFill = self.driver.find_element(By.XPATH, "//*[@name='premiumCommitment']") premiumCommitFill.send_keys("100000") print("Sum Assured Filled") annuityOption = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[16]") annuityOption.click() time.sleep(1) annuityOptions = self.driver.find_element(By.XPATH, "//*[@id='liId_Single Life']") annuityOptions.click() print("Annuity Selected") time.sleep(1) singleLifeAnnuity = self.driver.find_element(By.XPATH, "(//*[contains(text(),'Single Life Immediate Annuity for live')])[1]") singleLifeAnnuity.click() investorDropdownSelected= self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[18]") investorDropdownSelected.click() print("Investor dropdown Clicked") time.sleep(2) optionInvestorDropdownSelected = self.driver.find_element(By.XPATH, "//*[@id='liId_I am comfortable taking on a higher level of risk, knowing it may mean higher returns.']") optionInvestorDropdownSelected.click() print("Investor dropdown Selected") time.sleep(2) investmentDropdownSelected = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[19]") investmentDropdownSelected.click() print("Investment dropdown Clicked") optionInvestmentDropdownSelected = self.driver.find_element(By.XPATH, "//*[@id='liId_Portfolio 1 : Equity - 100%- Debt- 0%']") optionInvestmentDropdownSelected.click() print("Investment Selected") investmentDropdownUp = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[20]") investmentDropdownUp.click() print("Investment dropdown Clicked") optionInvestmentDropdownUp = self.driver.find_element(By.XPATH, "//*[@id='liId_30%']") optionInvestmentDropdownUp.click() print("Investment Up Selected") habitDescription = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[21]") habitDescription.click() print("Habit dropdown Clicked") optionHabitDescription = self.driver.find_element(By.XPATH, "//*[@id='liId_I am able to save substantial amount regularly, after covering living expenses.']") optionHabitDescription.click() print("Habit Selected") buttonProceedClick = self.driver.find_element(By.XPATH, "//*[contains(text(),'Proceed')]") buttonProceedClick.click() # self.wait.until(EC.element_to_be_clickable((By.XPATH, "(//*[@id='popupProceed'])[1]"))) # buttonYes= self.driver.find_element(By.XPATH, "(//*[@id='popupProceed'])[1]") # buttonYes.click() time.sleep(2) self.driver.switch_to_window(windowBefore) time.sleep(2) self.wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@name='fatherName']"))) fatherNameFill= self.driver.find_element(By.XPATH, "//*[@name='fatherName']") fatherNameFill.send_keys("Father") motherNameFill = self.driver.find_element(By.XPATH, "//*[@name='motherName']") motherNameFill.send_keys("Mother") maritalStatus = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[2]") maritalStatus.click() time.sleep(1) optionInMaritalStage = self.driver.find_element(By.XPATH, "//*[contains(text(), 'Married')]") optionInMaritalStage.click() print("Single Selected") educationSelect = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[3]") educationSelect.click() time.sleep(1) optionInEducationDropdown= self.driver.find_element(By.XPATH, "//*[contains(text(), 'Professional')][1]") optionInEducationDropdown.click() print("Education Selected") industrySelect= self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[4]") industrySelect.click() time.sleep(1) optionInIndustrySelect = self.driver.find_element(By.XPATH, "//*[contains(text(), 'Merchant')][1]") optionInIndustrySelect.click() print("Industry Selected") organisationSelect = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[5]") organisationSelect.click() time.sleep(1) optionInOrganisationSelect = self.driver.find_element(By.XPATH, "//*[@id='liId_Govt']") optionInOrganisationSelect.click() print("Organisation Selected") natureSelect = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[6]") natureSelect.click() time.sleep(1) optionInNatureSelect = self.driver.find_element(By.XPATH, "//*[@id='liId_Cargo Vessel']") optionInNatureSelect.click() print("Nature Selected") organisationFill = self.driver.find_element(By.XPATH, "//*[@name='companyName']") organisationFill.send_keys("ORG") preferredLanguage= self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[7]") preferredLanguage.click() time.sleep(1) optionInPreferredLanguage = self.driver.find_element(By.XPATH, "//*[@id='liId_Hindi']") optionInPreferredLanguage.click() print("Hindi Selected") time.sleep(2) organisationFill = self.driver.find_element(By.XPATH, "//*[@name='nomineeName']") organisationFill.send_keys("Nominee") calendarNomineeFill = self.driver.find_element(By.XPATH, "//*[@name='nomineeDateOfBirth']") calendarNomineeFill.click() yearNomineeDropdown = self.driver.find_element(By.XPATH, "//*[@class='react-datepicker__year-select']") yearNomineeSel = Select(yearNomineeDropdown) yearNomineeSel.select_by_value('1985') monthNomineeDropdown = self.driver.find_element(By.XPATH, "//*[@class='react-datepicker__month-select']") monthNomineeSel = Select(monthNomineeDropdown) monthNomineeSel.select_by_value('3') dateNomineeSel = self.driver.find_element(By.XPATH, "//*[@aria-label='day-10']") dateNomineeSel.click() genderSelected = self.driver.find_element(By.XPATH, "//*[contains(text(),'Male')]") genderSelected.click() print("Gender Clicked") relationshipProposer = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[9]") relationshipProposer.click() time.sleep(1) optionInRelationshipProposer= self.driver.find_element(By.XPATH, "//*[@id ='liId_Brother']") optionInRelationshipProposer.click() print("Relationship Brother Selected.") # specificRelationship = self.driver.find_element(By.XPATH, "(//*[@ tabindex='0'])[10]") # specificRelationship.click() # time.sleep(1) # optioninspecificRelationship = self.driver.find_element(By.XPATH, "//*[@id ='liId_Grand Father']") # optioninspecificRelationship.click() # time.sleep(1) # enterNomination = self.driver.find_element(By.XPATH, "//*[@name= 'nominationReason']") # enterNomination.send_keys("Hello") # time.sleep(1) bankFill = self.driver.find_element(By.XPATH, "//*[@name='bankAccountNo']") bankFill.send_keys("99999999999999") nameOfAccount = self.driver.find_element(By.XPATH, "//*[@name='bankAccountHolderName']") nameOfAccount.send_keys("NameName") nameOfIFSCcode = self.driver.find_element(By.XPATH, "//*[@name='bankAccountIFSC']") nameOfIFSCcode.send_keys("SBIN0000845") codeMICR = self.driver.find_element(By.XPATH, "//*[@name='bankAccountMICR']") codeMICR.send_keys("515002206") time.sleep(3) accountType = self.driver.find_element(By.XPATH, "(//*[@tabindex='0'])[11]") accountType.click() time.sleep(2) accountTypeSelect = self.driver.find_element(By.XPATH, "//*[contains(text(), 'Savings')]") accountTypeSelect.click() print("Account Type Selected.") time.sleep(2) btnProceedOnPage3 = self.driver.find_element(By.XPATH, "//*[contains(text(),'Proceed')]") btnProceedOnPage3.click() time.sleep(5)
driver.get("http://127.0.0.1:5500/index.html") # Fills the input fields with data fname_input = driver.find_element_by_id("fname") fname_input.send_keys("first name") lname_input = driver.find_element_by_id("lname") lname_input.send_keys("last name") pid_input = driver.find_element_by_id("pid") pid_input.send_keys("38703181745") program_input = driver.find_element_by_id("program") program_object = Select(program_input) program_object.select_by_value("computer-engineering") driver.find_element_by_css_selector( "input[type='radio'][value='male']").click() address_input = driver.find_element_by_id("address") address_input.send_keys("address") phone_input = driver.find_element_by_id("phone") phone_input.send_keys("864154545454545") driver.find_element_by_css_selector( "input[type='radio'][value='online']").click() # Press the submit button driver.find_element_by_css_selector("button[type='submit']").click()
def setManagerOfVendor(self, value): drp = Select( self.driver.find_element_by_xpath(self.drpmgrOfVendor_xpath)) drp.select_by_value(value)
import time from selenium import webdriver from selenium.webdriver.support.select import Select driver = webdriver.Chrome() driver.get( 'file:///D:/%E8%B0%A2%E5%BA%94%E5%85%B4' '/python%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81/pagetest/%E6%B3%A8%E5%86%8CA.html' ) select = Select(driver.find_element_by_id('selectA')) # 选择上海 #角标定位 time.sleep(2) select.select_by_index(1) # 选择广州 #根据值(value)定位 time.sleep(2) select.select_by_value('gz') # 选择北京 #文本定位 time.sleep(2) select.select_by_visible_text('北京') time.sleep(2) driver.quit()
def find_address(browser, road="中山北路", section="一", lan="126", l="", num="1", fl="", gg=""): def func(x): find = re.match('(.*鄰)(.*)', x) if find != None: print(find.group(2)) return find.group(2) # Insert address address = browser.find_element_by_name("ttrstreet") address.clear() address.send_keys(road) sec = Select(browser.find_element_by_name("ttrsection")) sec.select_by_value(section) lane = browser.find_element_by_name("ttrshi") lane.clear() lane.send_keys(lan) lo = browser.find_element_by_name("ttrlo") lo.clear() lo.send_keys(l) number = browser.find_element_by_name("ttrnum") number.clear() number.send_keys(num) floor = Select(browser.find_element_by_name("ttrfloor")) floor.select_by_value(fl) g = browser.find_element_by_name("ttrg") g.clear() g.send_keys(gg) sleep(1) button2 = browser.find_element_by_name("search") button2.click() try: browser.switch_to.alert.accept() browser.switch_to.parent_frame() browser.switch_to.frame("frm_new2") back = browser.find_element_by_xpath( '//a[@href="javascript:history.back()"]') back.click() return ["此地址", "查無結果"] except: browser.switch_to.parent_frame() browser.switch_to.frame("frm_new2") data = pd.read_html(browser.page_source) data = data[0] end = data[data.loc[:, 0].str.contains("本資料僅供參考,不作為其他證明使用")].index.values address_info = data.loc[2:end[0] - 1, 0].reset_index().loc[:, 0] address_info = address_info.map(lambda x: func(x)) back = browser.find_element_by_xpath( '//a[@href="javascript:history.back()"]') back.click() sleep(1) return address_info
def testSelectExample(self): SelectExample = self.driver.find_element_by_id("carselect") sel = Select(SelectExample) sel.select_by_value("honda") time.sleep(1)
def targeting(self, targeting="US_ONLY"): el = self.find_element(*self._targeting_select_locator) select = Select(el) select.select_by_value(targeting)