def test_operateMultipleOptionDropList(self):
     url = "http://127.0.0.1/test_multiple_select.html"
     # 访问自定义的html网页
     self.driver.get(url)
     # 导入Select模块
     from selenium.webdriver.support.ui import Select
     # 使用xpath定位方式获取select页面元素对象
     select_element = Select(self.driver.find_element_by_xpath("//select"))
     # 通过序号选择第一个元素
     select_element.select_by_index(0)
     # 通过选项的文本选择“山楂”选项
     select_element.select_by_visible_text("山楂")
     # 通过选项的value属性值选择value=“mihoutao”的选项
     select_element.select_by_value("mihoutao")
     # 打印所有的选中项文本
     for option in select_element.all_selected_options:
         print option.text
     # 取消所有已选中项
     select_element.deselect_all()
     time.sleep(2)
     print u"-----------再次选中3个选项--------------"
     select_element.select_by_index(1)
     select_element.select_by_visible_text("荔枝")
     select_element.select_by_value("juzi")
     # 通过选项文本取消已选中的文本为“荔枝”选项
     select_element.deselect_by_visible_text("荔枝")
     # 通过序号取消已选中的序号为1的选项
     select_element.deselect_by_index(1)
     # 通过选项的value属性值取消已选中的value=“juzi”的选项
     select_element.deselect_by_value("juzi")
Ejemplo n.º 2
0
 def test_operMutipleoptionsDropList(self):
     URL = 'F:\gitstorehouse\selenium3.0\webdriverAPI接口\测试页面\下拉框.html'
     self.driver.get(URL)
     from selenium.webdriver.support.ui import Select
     select_element = Select(self.driver.find_element_by_name('fruit'))
     #选择元素,多选
     select_element.select_by_index(1)
     select_element.select_by_visible_text('山楂')
     select_element.select_by_value('lizhi')
     for optins in select_element.all_selected_options:
         print(optins.text)
     #取消所选元素
     select_element.deselect_all()
     for optins in select_element.all_selected_options:
         print(optins.text)
     sleep(5)
     print('###########################################')
     #重新选择元素
     select_element.select_by_index(2)
     select_element.select_by_visible_text('山楂')
     select_element.select_by_value('lizhi')
     for optins in select_element.all_selected_options:
         print(optins.text)
     sleep(2)
     #取消选择元素
     select_element.deselect_by_index(1)
     select_element.deselect_by_value('lizhi')
     select_element.deselect_by_visible_text('山楂')
     sleep(5)
Ejemplo n.º 3
0
    def test_deselect_options(self):
        self.driver.get("http://toolsqa.com/automation-practice-form/")
        time.sleep(3)
        select_selenium_commands_element = self.driver.find_element_by_xpath(
            self.select_selenium_commands_xpath)

        select_selenium_commands = Select(select_selenium_commands_element)

        #select_options = select_education.options

        select_selenium_commands.select_by_index(0)
        select_selenium_commands.deselect_all()

        select_selenium_commands.select_by_index(1)
        select_selenium_commands.deselect_by_index(1)

        #<option>'s have no value attribute
        #select_selenium_commands.select_by_value("College")
        #select_selenium_commands.deselect_by_value("College")

        select_selenium_commands.select_by_visible_text("WebElement Commands")

        print("Selected option value: %s" %
              select_selenium_commands.first_selected_option.get_attribute(
                  "value"))
Ejemplo n.º 4
0
 def element_deselect(self, cls, type, value):
     '''取消下拉框勾选操作'''
     select = Select(self.get_element(cls))
     if (type == 'index'):
         select.deselect_by_index(value)
     elif (type == 'visible_text'):
         select.deselect_by_visible_text(value)
     elif (type == 'value'):
         select.dedeselect_by_value(value)
Ejemplo n.º 5
0
 def callback(elements):
     s = Select(elements.item)
     if i is not None:
         s.deselect_by_index(i)
     elif value is not None:
         s.deselect_by_value(value)
     elif text is not None:
         s.deselect_by_visible_text(text)
     else:
         s.deselect_all()
Ejemplo n.º 6
0
 def callback(elements):
     s = Select(elements.item)
     if i is not None:
         s.deselect_by_index(i)
     elif value is not None:
         s.deselect_by_value(value)
     elif text is not None:
         s.deselect_by_visible_text(text)
     else:
         s.deselect_all()
Ejemplo n.º 7
0
def Select_Options():
    select = Select(driver.find_elements_by_id())
    select.select_by_index()
    select.select_by_value()
    select.select_by_visible_text()
    select.deselect_by_index()
    select.deselect_by_value()
    select.deselect_by_visible_text()
    select.deselect_all()

    select.all_selected_options
    select.first_selected_option
    select.options
Ejemplo n.º 8
0
def testDeselectByIndexMultiple(driver, pages):
    pages.load("formPage.html")
    for select in [multiSelectValues1, multiSelectValues2]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        sel.deselect_all()
        sel.select_by_index(0)
        sel.select_by_index(1)
        sel.select_by_index(2)
        sel.select_by_index(3)
        sel.deselect_by_index(1)
        sel.deselect_by_index(3)
        selected = sel.all_selected_options
        assert len(selected) == 2
        assert selected[0].text == select['values'][0]
        assert selected[1].text == select['values'][2]
Ejemplo n.º 9
0
def testDeselectByIndexMultiple(driver, pages):
    pages.load("formPage.html")
    for select in [multiSelectValues1, multiSelectValues2]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        sel.deselect_all()
        sel.select_by_index(0)
        sel.select_by_index(1)
        sel.select_by_index(2)
        sel.select_by_index(3)
        sel.deselect_by_index(1)
        sel.deselect_by_index(3)
        selected = sel.all_selected_options
        assert len(selected) == 2
        assert selected[0].text == select['values'][0]
        assert selected[1].text == select['values'][2]
Ejemplo n.º 10
0
 def testDeselectByIndexMultiple(self):
     if self.driver.capabilities['browserName'] == 'chrome' and int(self.driver.capabilities['version'].split('.')[0]) < 16:
         pytest.skip("deselecting preselected values only works on chrome >= 16")
     self._loadPage("formPage")
     for select in [multiSelectValues1, multiSelectValues2]:
         sel = Select(self.driver.find_element(By.NAME, select['name']))
         sel.deselect_all()
         sel.select_by_index(0)
         sel.select_by_index(1)
         sel.select_by_index(2)
         sel.select_by_index(3)
         sel.deselect_by_index(1)
         sel.deselect_by_index(3)
         selected = sel.all_selected_options
         self.assertEqual(len(selected), 2)
         self.assertEqual(selected[0].text, select['values'][0])
         self.assertEqual(selected[1].text, select['values'][2])
Ejemplo n.º 11
0
 def testDeselectByIndexMultiple(self):
     if self.driver.capabilities['browserName'] == 'chrome' and int(self.driver.capabilities['version'].split('.')[0]) < 16:
         pytest.skip("deselecting preselected values only works on chrome >= 16")
     self._loadPage("formPage")
     for select in [multiSelectValues1, multiSelectValues2]:
         sel = Select(self.driver.find_element(By.NAME, select['name']))
         sel.deselect_all()
         sel.select_by_index(0)
         sel.select_by_index(1)
         sel.select_by_index(2)
         sel.select_by_index(3)
         sel.deselect_by_index(1)
         sel.deselect_by_index(3)
         selected = sel.all_selected_options
         self.assertEqual(len(selected), 2)
         self.assertEqual(selected[0].text, select['values'][0])
         self.assertEqual(selected[1].text, select['values'][2])
Ejemplo n.º 12
0
 def testDeselectByIndexMultiple(self, driver, pages):
     if driver.capabilities['browserName'] == 'chrome' and int(driver.capabilities['version'].split('.')[0]) < 16:
         pytest.skip("deselecting preselected values only works on chrome >= 16")
     pages.load("formPage.html")
     for select in [multiSelectValues1, multiSelectValues2]:
         sel = Select(driver.find_element(By.NAME, select['name']))
         sel.deselect_all()
         sel.select_by_index(0)
         sel.select_by_index(1)
         sel.select_by_index(2)
         sel.select_by_index(3)
         sel.deselect_by_index(1)
         sel.deselect_by_index(3)
         selected = sel.all_selected_options
         assert len(selected) == 2
         assert selected[0].text == select['values'][0]
         assert selected[1].text == select['values'][2]
 def test_operateMultipleOptionDropList(self):
     url = 'F:\\HTMLTest\\select.html'
     self.driver.get(url)
     select_element = Select(self.driver.find_element_by_xpath('//select'))
     select_element.select_by_index(0)
     select_element.select_by_visible_text('山楂')
     select_element.select_by_value('mihoutao')
     for option in select_element.all_selected_options:
         print(option.text)
     select_element.deselect_all()
     time.sleep(2)
     print('---------------- 再次选中 3 个选项 ------------------')
     select_element.select_by_index(1)
     select_element.select_by_visible_text('荔枝')
     select_element.select_by_value('juzi')
     select_element.deselect_by_visible_text('荔枝')
     select_element.deselect_by_index(1)
     select_element.deselect_by_value('juzi')
def test_selectedData(test_select, test_common):
    lists = test_common[0].find_element_by_id('select')
    s1 = Select(
        lists)  # use Select class pass lists as argument which is webelement.

    s2 = s1.options  # list of all data
    for i in range(0, len(s2)):
        if (i % 2 == 0):

            s1.select_by_index(i)
            text = s2[i].text
            print(text)
            time.sleep(1)
            s1.deselect_by_index(i)
            time.sleep(1)

    time.sleep(2)
    test_common[0].close()
Ejemplo n.º 15
0
    def testOperateMultiDropdownlist(self):
        driver = self.driver
        WebSite = os.path.join(os.path.abspath('..'), 'Html', '10.23.html')
        driver.get(WebSite)
        time.sleep(2)  #等待2秒

        from selenium.webdriver.support.ui import Select  #导入Select模块
        Dropdownlist = Select(
            driver.find_element_by_xpath("//select"))  #用xpath方法定位多选下拉列表
        time.sleep(2)

        Dropdownlist.select_by_index(0)  #使用select_by_index()方法,通过序号选择第一个元素
        time.sleep(2)

        Dropdownlist.select_by_visible_text(
            'Jenson Button'
        )  #使用select_by_visible_text()方法,通过选项的文本选择"Jenson Button"
        time.sleep(2)

        Dropdownlist.select_by_value(
            'Ham')  #使用select_by_value()方法,通过选项的value值'Ham',选择"Lewis Hamilton"
        time.sleep(2)

        for MyDriver in Dropdownlist.all_selected_options:  #遍历循环,利用all_selected_options方法,打印所有已经被选中的选项
            print(MyDriver.text)
            time.sleep(2)

        Dropdownlist.deselect_all()  #使用deselect_all()方法,取消选择所有已选中的内容
        time.sleep(2)

        Dropdownlist.select_by_index(1)  #随意选择三个选项
        Dropdownlist.select_by_visible_text('Sebastian Vettel')
        Dropdownlist.select_by_value('Rai')
        time.sleep(2)

        Dropdownlist.deselect_by_index(
            1)  #使用deselect_by_index()方法,通过序号取消选择第二个元素
        Dropdownlist.deselect_by_visible_text(
            'Sebastian Vettel'
        )  #使用deselect_by_visible_text()方法,通过选项的文本取消选择"Sebastian Vettel"
        Dropdownlist.deselect_by_value(
            'Rai'
        )  #使用deselect_by_value()方法,通过选项的value值'Rai',取消选择"Kimi Raikkonen"
        time.sleep(2)
Ejemplo n.º 16
0
 def testDeselectByIndexMultiple(self, driver, pages):
     if driver.capabilities['browserName'] == 'chrome' and int(
             driver.capabilities['version'].split('.')[0]) < 16:
         pytest.skip(
             "deselecting preselected values only works on chrome >= 16")
     pages.load("formPage.html")
     for select in [multiSelectValues1, multiSelectValues2]:
         sel = Select(driver.find_element(By.NAME, select['name']))
         sel.deselect_all()
         sel.select_by_index(0)
         sel.select_by_index(1)
         sel.select_by_index(2)
         sel.select_by_index(3)
         sel.deselect_by_index(1)
         sel.deselect_by_index(3)
         selected = sel.all_selected_options
         assert len(selected) == 2
         assert selected[0].text == select['values'][0]
         assert selected[1].text == select['values'][2]
Ejemplo n.º 17
0
    def test_select(self):
        driver = self.driver

        # selection 태그에서 옵션의 개수 확인
        cars = Select(driver.find_element_by_name("multi_cars"))
        self.assertEqual(4, len(cars.options))

        # ctrl + click 효과 _ multiple choice
        cars.select_by_visible_text("Volvo")
        cars.select_by_value("multi_saab")
        cars.select_by_index(2)
        cars.select_by_index(3)
        time.sleep(2)
        # 선택 취소
        cars.deselect_by_visible_text("Volvo")
        cars.deselect_by_value("multi_saab")
        cars.deselect_by_index(2)
        cars.deselect_by_index(3)
        time.sleep(2)
    def _lookupClass_page_(self, numOfQuarters):
        from selenium.webdriver.support.ui import Select

        for termIndex in range(
                1, (numOfQuarters +
                    1)):  # 3quarter = range(1, 4) position[0] is [Term:NULL]
            # Term Selection Page
            select_box_term = Select(
                self._driver.find_element_by_id("term_input_id"))

            # Set quarter
            select_box_term.select_by_index(termIndex)
            self._driver.find_element_by_xpath(
                "//div[3]/form[1]/input[2]").click()
            # =====================================================================

            select_box_subject = Select(
                self._driver.find_element_by_xpath(
                    '//div[3]/form[1]/table[1]/tbody[1]/tr[1]/td[2]/select[@name="sel_subj"]'
                ))
            subjectNum = len(select_box_subject.options)
            for subjectIndex in range(subjectNum):

                # Subject Selection Page
                select_box_subject = Select(
                    self._driver.find_element_by_xpath(
                        '//div[3]/form[1]/table[1]/tbody[1]/tr[1]/td[2]/select[@name="sel_subj"]'
                    ))

                # print(option.text, option.get_attribute('value'))
                if subjectIndex > 0:
                    select_box_subject.deselect_by_index((subjectIndex - 1))
                select_box_subject.select_by_index(subjectIndex)
                self._driver.find_element_by_xpath(
                    "//div[3]/form[1]/input[17]").click()

                # Navigate Course Page
                self._course_page_()
                self._driver.back()  # back from course page to subject page
                #time.sleep(0.5)

            self._driver.back()  # back from subject page to term page
            time.sleep(1)
Ejemplo n.º 19
0
	def test_operateMultipleOptionDropList(self):
		url = "file:///C:/Users/Administrator/Desktop/seleniumTestCase/23test.html"
		self.driver.get(url)
		from selenium.webdriver.support.ui import Select
		select_element = Select(self.driver.find_element_by_xpath("//select"))
		select_element.select_by_visible_text("shanzha")
		select_element.select_by_value("mihoutao")
		for option in select_element.select.all_selected_options:
			print option.text
		select_element.deselect_all()
		time.sleep(2)
		print "----3----"
		select_element.select_by_index()
		select_element.select_by_visible_text("lizhi")
		select_element.select_by_value("juzi")

		select_element.deselect_by_visible_text("lizhi")
		select_element.deselect_by_index(1)
		select_element.deselect_by_value("juzi")
		time.sleep(3)
Ejemplo n.º 20
0
def main():
    # Select Fall 2019 in form
    sel_term = Select(driver.find_elements_by_name("term_code")[0])
    sel_term.select_by_value("201909")

    # Continues to next page with Fall 2019 Term
    button = driver.find_element_by_xpath("//input[@type='submit']")
    button.submit()

    # Used to get total number of subjects
    sel_subject = Select(driver.find_elements_by_name("sel_subj")[1])

    # Iterate through every index in subject
    for x in range(1, len(sel_subject.options)):

        # Select subject
        sel_subject = Select(driver.find_elements_by_name("sel_subj")[1])
        sel_subject.select_by_index(x)
        sel_subject.deselect_by_index('0')

        # Select Abbotsford Campus
        sel_campus = Select(driver.find_elements_by_name("sel_camp")[1])
        sel_campus.deselect_all()
        sel_campus.select_by_visible_text("Abbotsford")

        # Submit form
        button2 = driver.find_elements_by_xpath("//input[@type='submit']")[0]
        button2.submit()

        # If no courses in subject do not scrape
        if len(driver.find_elements_by_xpath(
                "//span[@class='warningtext']")) != 0:
            print("No courses here!")
            return_to_subjects()
            continue

        # Calls function to scrape all course data
        scrape_page()

        # Once complete, return back to course selection
        return_to_subjects()
Ejemplo n.º 21
0
	def test_multiple_selection_in_list(self):
		driver = self.driver
		
	 	#Get the Dropdown as a Select using it's name attribute
 		color = Select(driver.find_element_by_name("color"))
		
		#Verify Dropdown has four options for selection
		self.assertEqual(5,len(color.options))
		
		#Select multiple options in the list using visible text
		color.select_by_visible_text("Black")
		color.select_by_visible_text("Red")
		color.select_by_visible_text("Silver")
		
		#Deselect an option using visible text
		color.deselect_by_visible_text("Silver")
    	
		#Deselect an option using value attribute of the option
		color.deselect_by_value("rd")
		
		#Deselect an option using index of the option
		color.deselect_by_index(0)
Ejemplo n.º 22
0
    def test_multiple_selection_in_list(self):
        driver = self.driver

        #Get the Dropdown as a Select using it's name attribute
        color = Select(driver.find_element_by_name("color"))

        #Verify Dropdown has four options for selection
        self.assertEqual(5, len(color.options))

        #Select multiple options in the list using visible text
        color.select_by_visible_text("Black")
        color.select_by_visible_text("Red")
        color.select_by_visible_text("Silver")

        #Deselect an option using visible text
        color.deselect_by_visible_text("Silver")

        #Deselect an option using value attribute of the option
        color.deselect_by_value("rd")

        #Deselect an option using index of the option
        color.deselect_by_index(0)
Ejemplo n.º 23
0
    def select_option(self, obj):
        # Set local parameters
        step = obj.get('order')
        identifier_dict = obj.get('identifier')
        if identifier_dict is None:
            raise Exception('No identifier')
        child_window = obj.get('child_window')
        if child_window is None:
            raise Exception('No child_window')
        selection_value = obj.get('selection_value')
        if selection_value is None:
            raise Exception('No selection_value')
        selection_type = obj.get('selection_type')
        if selection_type is None:
            raise Exception('No selection_type')
        multiline = obj.get('multiline')
        action = None

        element = self.ei.uniquely_identify_element(identifier_dict)

        # Report no element found
        if element is None:
            action = 'No element found'
            return action

        if element is not None:

            # Prepare element for action
            self.__wait_for_post_back_to_complete(element, obj.get('timeout'))
            self.driver.execute_script('return arguments[0].scrollIntoView();', element)
            self.driver.execute_script(' window.scrollBy(0, -100);')
            selection = Select(element)
            options = selection.options
            acted_upon_options = self.__determine_acted_upon_option(options, selection_value, selection_type)

            # Determine how we are interacting with the select
            if selection_type.lower() == "index":
                action = "Select '" + acted_upon_options + "' from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.select_by_index(selection_value)
            elif selection_type.lower() == "text":
                action = "Select '" + acted_upon_options + "' from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.select_by_visible_text(selection_value)
            elif selection_type.lower() == "value":
                action = "Select '" + acted_upon_options + "' from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.select_by_value(selection_value)
            elif selection_type.lower() == "deindex":
                action = "Deselect '" + acted_upon_options + "' from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.deselect_by_index(selection_value)
            elif selection_type.lower() == "detext":
                action = "Deselect '" + acted_upon_options + "' from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.deselect_by_visible_text(selection_value)
            elif selection_type.lower() == "devalue":
                action = "Deselect '" + acted_upon_options + "' from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.deselect_by_value(selection_value)
            elif selection_type.lower == "deall":
                action = "Deselected all values from the '" + str(
                    self.find_html_for(element.get_attribute('id'))) + "' dropdown"
                selection.deselect_all()
            else:
                # This should really just be reported and not raise an exception
                raise Exception("Unknown selection type.")

        # Determine if action changes browser count
        if child_window:
            self.change_window_connection()

        print(action)
        return action
Ejemplo n.º 24
0
 def test_deselect_option_multiple(self):
     select_box = Select(self.driver.find_element_by_name("test_framework"))
     select_box.select_by_visible_text("Selenium")
     select_box.select_by_value("rwebspec")
     select_box.deselect_by_visible_text("RWebSpec")  # by label
     select_box.deselect_by_index(3)  # :index
Ejemplo n.º 25
0
driver.find_element_by_xpath('//a[contains(@href,"dropdown")]').click()

dropdown = driver.find_element_by_xpath('//select[@name="country"]')
select = Select(dropdown)
select.select_by_index(3)
time.sleep(4)
select.select_by_value("IN")
time.sleep(3)
select.select_by_visible_text("Australia")
time.sleep(2)

dropdown_multi = driver.find_element_by_xpath('//select[@id="multiSelect"]')
select = Select(dropdown_multi)
select.select_by_value("AS")
time.sleep(2)
select.select_by_index(2)
time.sleep(3)
select.select_by_visible_text("Angola")
select.select_by_value("IN")
time.sleep(5)
select.deselect_by_visible_text("Albania")
select.deselect_by_index(6)
select.deselect_by_value("AS")
# print(select.first_selected_option.text)
# all_selected_options = select.all_selected_options
# print(all_selected_options)
# select.deselect_all()
#
# for current_option in all_selected_options:
#     print(current_option.text)
Ejemplo n.º 26
0
class Select(Action):

    def __init__(self, driver, locator=None, element=None, wait_time=10, visible=False):
        super().__init__(driver, locator, element, wait_time, visible)
        self.dropdown = Select_(self.element)
    
    def select_all(self):
        all_elements = self.dropdown.options
        if not all_elements:
            return
        for ele in all_elements:
            if not ele.is_selected():
                ele.click()
        
    def select_by_visible_texts(self, values=""):
        values = self._convert(values)
        for value in values:
            self.dropdown.select_by_visible_text(value)
        return self
    
    def select_by_indices(self, indices):
        indices = self._convert(indices)
        for index in indices:
            self.dropdown.select_by_index(index)
        return self

    def select_by_values(self, values=""):
        values = self._convert(values)
        for value in values:
            self.dropdown.select_by_value(value)
        return self
    
    def deselect_all(self):
        self.dropdown.deselect_all()
    
    def deselect_by_visible_texts(self, values=""):
        values = self._convert(values)
        for value in values:
            self.dropdown.deselect_by_visible_text(value)
        return self
    
    def deselect_by_indices(self, indices):
        indices = self._convert(indices)
        for index in indices:
            self.dropdown.deselect_by_index(index)
        return self

    def deselect_by_values(self, values=""):
        values = self._convert(values)
        for value in values:
            self.dropdown.deselect_by_value(value)
        return self
    
    @property
    def options_text(self):
        #get can be text, value, element
        all_elements = self.dropdown.options
        results = self._get_options(all_elements, "text")
        return results
    
    @property
    def options_value(self):
        #get can be text, value, element
        all_elements = self.dropdown.options
        results = self._get_options(all_elements, "value")
        return results

    @property
    def options_element(self):
        #get can be text, value, element
        all_elements = self.dropdown.options
        results = self._get_options(all_elements, "element")
        return results
    
    @property
    def all_selected_options_text(self):
        #get can be text, value, element
        all_elements = self.dropdown.all_selected_options
        results = self._get_options(all_elements, "text")
        return results
    
    @property
    def all_selected_options_value(self):
        #get can be text, value, element
        all_elements = self.dropdown.all_selected_options
        results = self._get_options(all_elements, "value")
        return results
    
    @property
    def all_selected_options_element(self):
        #get can be text, value, element
        all_elements = self.dropdown.all_selected_options
        results = self._get_options(all_elements, "element")
        return results
    
    def _get_options(self, all_elements, get):
        results = []
        if not all_elements:
            return results
        if "text" in get.strip().lower():
            for ele in all_elements:
                results.append(ele.text)
        elif "value" in get.strip().lower():
            for ele in all_elements:
                results.append(ele.get_attribute('value'))
        elif "element" in get.strip().lower():
            results = all_elements
        else:
            get_logger().error("Invalid input. Valid values for get - text, value, element")
            raise InvalidArgumentError("Invalid input. Valid values for get - text, value, element")
        return results
    
    def _convert(self, values):
        if not values:
            values = []
        if not isinstance(values, list):
            values = [values]
        return values
Ejemplo n.º 27
0
driver = webdriver.Chrome('/Users/vigneshnatarajan/Downloads/chromedriver')

driver.get('https://nces.ed.gov/collegenavigator/')

WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(
        (By.XPATH, '//*[@id="LeftContent"]/div[2]/div[6]')))

schools, grad_4_10, grad_4_12, grad_6_10, grad_6_12 = [], [], [], [], []
for count in range(1, 52):
    states = Select(
        driver.find_element_by_xpath(
            '//*[@id="ctl00_cphCollegeNavBody_ucSearchMain_ucMapMain_lstState"]'
        ))
    states.deselect_by_index(0)
    states.select_by_index(count)

    bachelors = driver.find_element_by_xpath(
        '//*[@id="ctl00_cphCollegeNavBody_ucSearchMain_chkBach"]')
    bachelors.click()
    time.sleep(2)

    four_year = driver.find_element_by_xpath(
        '//*[@id="ctl00_cphCollegeNavBody_ucSearchMain_chkLevelFourYear"]')
    four_year.click()
    time.sleep(2)

    results = driver.find_element_by_xpath(
        '//*[@id="ctl00_cphCollegeNavBody_ucSearchMain_btnSearch"]')
    results.click()
Ejemplo n.º 28
0
class Select(BaseElement):
    """
    A web select
    """
    def __init__(self, element):
        BaseElement.__init__(self, element)
        self._select = WDSelect(self._element)

    @property
    def options(self):
        """
        obtains all options in the select element

        :return: all options in the select element
        :rtype: list
        """
        inner_options = self._select.options
        options = []
        for option_se in inner_options:
            options.append(selenium_web_element_to_element(option_se))
        return options

    @property
    def selected_options(self):
        """
        obtains all options selected

        :return: all options selected in the select element
        :rtype: list
        """
        inner_options = self._select.all_selected_options
        options = []
        for option_se in inner_options:
            options.append(selenium_web_element_to_element(option_se))
        return options

    @property
    def first_selected_option(self):
        """
        obtains the first option selected

        :return: the first option selected in the select element
        :rtype: BaseElement
        """
        option = self._select.first_selected_option
        return selenium_web_element_to_element(option)

    def select_by_index(self, index):
        """
        Selects an option by its index

        :param index: the index to be searched
        """
        return self._select.select_by_index(index)

    def select_by_value(self, value):
        """
        Selects an option by its value

        :param value: the value to be searched
        """
        return self._select.select_by_value(value)

    def select_by_visible_text(self, text):
        """
        Selects an option by its visible text

        :param text: the value to be searched
        """
        return self._select.select_by_visible_text(text)

    def deselect_all(self):
        """
        Deselects all selected options
        """
        self._select.deselect_all()

    def deselect_by_index(self, index):
        """
        Deselects an option by its index

        :param index: the index to be searched
        """
        self._select.deselect_by_index(index)

    def deselect_by_value(self, value):
        """
        Selects an option by its value

        :param value: the value to be searched
        """
        self._select.deselect_by_value(value)

    def deselect_by_visible_text(self, text):
        """
        Deselects an option by its visible text

        :param text: the value to be searched
        """
        self._select.deselect_by_visible_text(text)