Action drop-down list
<HTML><Body> <Selectname= ' Fruit 'size=6> <optionID= ' Peach 'value= ' Taozi '>Peach</option> <optionID= ' Maybush 'value= ' Shanzha '>Hawthorn</option> <optionID= ' Litchi 'value= ' Lizhi '>Litchi</option> <optionID= ' Orange 'value= ' Juzi '>Orange</option> </Select></Body></HTML>
@Test Public voidoperatedroplist () {Select droplist=NewSelect (Driver.findelement (By.name ("Fruit"))); //determine if the drop-down list can be checked, because it is a single-selection list so use false, more true;Assert.assertfalse (Droplist.ismultiple ()); //getfirstselectedoption () method gets the drop-down list of the first property, the GetText () method gets the option text textAssert.assertequals ("Peach", Droplist.getfirstselectedoption (). GetText ()); //The drop-down option is locked by the serial number, starting from 0 as the first drop-down element;Droplist.selectbyindex (3); //Select operation with value valuesDroplist.selectbyvalue ("Shanzha"); //Droplist.selectbyindex (3). GetText () method error, accounting for what reason, are quoted Droplist.getfirstselectedoption (). GetText () to assert//assert.assertequals ("Hawthorn", Droplist.selectbyindex (3). GetText ()); //selected by option text, Droplist.selectbyvisibletext ("Lychee"). GetText () error;//assert.assertequals ("Litchi", Droplist.selectbyvisibletext ("Litchi"). GetText ());List<string>expect_options=arrays.aslist ((Newstring[]{"Peach", "Hawthorn", "lychee", "Orange"})); List<string>actual_options=NewArraylist<string>(); //droplist.getoptions () Get drop-down list all options text for(Webelement option:dropList.getOptions ()) {Actual_options.add (Option.gettext ()); } assert.assertequals (Expect_options.toarray (), Actual_options.toarray ()); //The multi-Select drop-down list method is also ibid, note assertion multiple select Droplist.ismultiple () use Asserttrue ()
Droplist.deselectbyindex (0); Remove the option for the first drop-down element
Webdriver--api--(Java edition) the second part