| 780 | assert len(select.options) == 0 |
| 781 | |
| 782 | def test_select_element_add(self): |
| 783 | # GIVEN the existing select element with no options |
| 784 | select = web.page.find("#test_select_element")[0] |
| 785 | |
| 786 | # EXPECT the select element to have no options |
| 787 | assert len(select.options) == 0 |
| 788 | |
| 789 | # WHEN we add an option |
| 790 | select.options.add(value="1", html="Option 1") |
| 791 | |
| 792 | # EXPECT the select element to have 1 option matching the attributes |
| 793 | # we passed in |
| 794 | assert len(select.options) == 1 |
| 795 | assert select.options[0].value == "1" |
| 796 | assert select.options[0].innerHTML == "Option 1" |
| 797 | |
| 798 | # WHEN we add another option (blank this time) |
| 799 | select.options.add("") |
| 800 | |
| 801 | # EXPECT the select element to have 2 options |
| 802 | assert len(select.options) == 2 |
| 803 | |
| 804 | # EXPECT the last option to have an empty value and html |
| 805 | assert select.options[1].value == "" |
| 806 | assert select.options[1].innerHTML == "" |
| 807 | |
| 808 | # WHEN we add another option (this time adding it in between the other 2 |
| 809 | # options by using an integer index) |
| 810 | select.options.add(value="2", html="Option 2", before=1) |
| 811 | |
| 812 | # EXPECT the select element to have 3 options |
| 813 | assert len(select.options) == 3 |
| 814 | |
| 815 | # EXPECT the middle option to have the value and html we passed in |
| 816 | assert select.options[0].value == "1" |
| 817 | assert select.options[0].innerHTML == "Option 1" |
| 818 | assert select.options[1].value == "2" |
| 819 | assert select.options[1].innerHTML == "Option 2" |
| 820 | assert select.options[2].value == "" |
| 821 | assert select.options[2].innerHTML == "" |
| 822 | |
| 823 | # WHEN we add another option (this time adding it in between the other 2 |
| 824 | # options but using the option itself) |
| 825 | select.options.add( |
| 826 | value="3", html="Option 3", before=select.options[2], selected=True |
| 827 | ) |
| 828 | |
| 829 | # EXPECT the select element to have 3 options |
| 830 | assert len(select.options) == 4 |
| 831 | |
| 832 | # EXPECT the middle option to have the value and html we passed in |
| 833 | assert select.options[0].value == "1" |
| 834 | assert select.options[0].innerHTML == "Option 1" |
| 835 | assert select.options[0].selected == select.options[0]._dom_element.selected |
| 836 | assert select.options[0].selected is False |
| 837 | assert select.options[1].value == "2" |
| 838 | assert select.options[1].innerHTML == "Option 2" |
| 839 | assert select.options[2].value == "3" |