def getValue(self): if self.__tag == "select": select = Select(self.__element) return select.all_selected_options( ) #返回是一个列表,所有被选中的项目放在列表里,option的列表 else: return self.__element.text
def dropdown_selectall(self, element): varA = Select(element) varA.all_selected_options()
def parse(url): global count_add, count_no_add, cpus print("Запуск браузера") driver = init_driver() print("Переход на страницу:", url) driver.get(url) select_deskornote = driver.find_element_by_css_selector( 'select[name = "deskornote"]') select_deskornote.click() options = select_deskornote.find_elements_by_css_selector('option') for option in options: if (option.text == "Show all GPUs"): option.click() break select_professional = driver.find_element_by_css_selector( 'select[name = "professional"]') select_professional.click() options = select_professional.find_elements_by_css_selector('option') for option in options: if (option.text == "Consumer and Professional GPUs"): option.click() break select_multiplegpus = driver.find_element_by_css_selector( 'select[name = "multiplegpus"]') select_multiplegpus.click() options = select_multiplegpus.find_elements_by_css_selector('option') for option in options: if (option.text == "Single and multiple GPUs"): option.click() break select_games = Select( driver.find_element_by_css_selector('#bl_gameselect')) select_games.all_selected_options() input_button = driver.find_element_by_css_selector( 'input[type="submit"]').click() time.sleep(20) # trs = driver.find_elements_by_css_selector('table>tbody>tr[style = "display: table-row;"') # count_cpu = len(trs) # print(count_cpu) # for index, tr in enumerate(trs): # tds = tr.find_elements_by_css_selector('td') # name_cpu = tds[0].find_elements_by_css_selector('a')[1].text # if(name_cpu.find("Intel Core2") != -1): # name_cpu = name_cpu.replace("Intel Core2", "Intel Core 2") # single_thread = tds[4].text # if (single_thread == "NA"): # single_thread = None # # multi_thread = tds[2].text # # id_product = get_product_id(name_cpu, "cpu") # if(id_product != None): # add_cpu_benchmark(id_product, id_brenchmark_cpu, single_thread,multi_thread) # count_add += 1 # print("Добавлен в БД:",[id_product, id_brenchmark_cpu, single_thread,multi_thread]) # else: # id_product = search_best_conformity(name_cpu, "cpu") # if (id_product != None): # # id_cpu_brenchmark_value_one = add_cpu_benchmark(id_product, id_brenchmark_cpu, single_thread, multi_thread) # count_add += 1 # print("Добавлен в БД:", [name_cpu, single_thread, multi_thread]) # else: # count_no_add += 1 # cpus.append([name_cpu, single_thread, multi_thread]) # print("Добавлен в список недобавленных:", [name_cpu, single_thread, multi_thread]) driver.close()
x = driver.find_element_by_id('RESULT_RadioButton-9') drop = Select(x) drop.is_multiple() # Select by index drop.select_by_index(2) drop.select_by_visible_text('') drop.select_by_value('') drop.deselect_all() drop.deselect_by_index(0) drop.deselect_by_value('') drop.deselect_by_visible_text('') drop.options() drop.first_selected_option() drop.all_selected_options() # Action class # create action chain object action = ActionChains(driver) menu = driver.find_element_by_css_selector(".nav") hidden_submenu = driver.find_element_by_css_selector(".nav # submenu1") action.click(menu).perform() action.context_click(menu).perform() action.double_click(menu).perform() action.click_and_hold(menu).perform() action.send_keys(menu).perform() action.send_keys_to_element(menu, Keys.ENTER).perform()