您的位置:首页 > 编程语言 > Python开发

python循环嵌套遍历前后关联的select下拉框

2016-06-14 15:19 435 查看
        select = driver.find_element_by_id("id_num")

        options_list = select.find_elements_by_tag_name("option")

        time.sleep(2)

        count_option = 0

        for option in options_list:

            value = option.get_attribute("value")

            text = option.text

            filename = text.encode("utf-8")+".txt"

            f = open(unicode("D:\\temp\\123_loop\\" + filename, "utf-8"), "w+")

            # print "Value is: " + value

            # print "Text is:" + text

            # print "count_option" + str(count_option)

            driver.find_element_by_id("id_num").find_elements_by_tag_name("option")[count_option].click()

            count_option += 1

            time.sleep(4)

            select2 = driver.find_element_by_id("id_num2")

            options_list2 = select2.find_elements_by_tag_name("option")

            count = 0

            for option2 in options_list2:

                value2 = option2.get_attribute("value")

                text2 = [option2.text+'\n']

                # print "Value2 is: " + value2

                # print "Text2 is:" + text2

                driver.find_element_by_id("id_num2").find_elements_by_tag_name("option")[count].click()

                time.sleep(3)

                f.writelines(text2[0].encode("utf-8"))

                count += 1

            f.writelines('\n数据总数:'+str(count))

            f.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息