Webdriver--api--(Java edition) the second part

Source: Internet
Author: User
Tags droplist

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.