Summary of positioning methods of select-option tags in C # selenium

Source: Internet
Author: User

To locate the Select-option structure on the page, try the following methods, none of them are effective:

IW. Findelement (By.cssselector ("Select#id > Option[value=")). Click (); //IW. Findelement (By.xpath ("//select[@id = ']/option[@value = ']")). Click (); //IW. Findelements (by.tagname ("option")) [index]. Click ();      

Finally, the Select-option label on the page was successfully located in the following way:

var selector = IW. Findelement (By.id (""new selectelement (selector);  Select. Selectbytext ("text");      

Select objects can be positioned on an element by using attributes such as option Value,text.

Practical applications, such as when creating a site in SharePoint, for site template selection and site path choice:

Public Iwebdriver Createspsite (Iwebdriver IW,String Caurl,String title,StringTemplate) {String createsitepage = Caurl +"/_admin/createsite.aspx"; Iw. Navigate (). Gotourl (Createsitepage); Waituntilpageloadedid (IW,"Ctl00_placeholdermain_ctl02_rptcontrols_btncreatesite");//Title. Iw. Findelement (By.id ("Ctl00_placeholdermain_idtitledescsection_ctl01_txtcreatesitetitle")). SendKeys (title);//Url.var paths = IW. Findelement (By.id ("ctl00_placeholdermain_ctl01_ctl04_ddlwildcardinclusion")); SelectElement Path = new selectelement (paths); Path. Selectbytext ("/sites/"); Waituntilpageloadedid (IW,"Ctl00_placeholdermain_ctl01_ctl04_txtsitename"); Iw. Findelement (By.id ("Ctl00_placeholdermain_ctl01_ctl04_txtsitename")). SendKeys (title);Switch(template) {Case"Ts":Break;Case"Edi": IW. Findelement (By.id ("Ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_tabid1")). Click (); Thread.Sleep (1000); Waituntilpageloadedid (IW,"Ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_lbwebtemplate");var selector = IW. Findelement (By.id ("ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_lbwebtemplate")); SelectElement select = new SelectElement (selector); Select. Selectbytext ("EDiscovery Center");Break;Case"Rc": IW. Findelement (By.id ("Ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_tabid1")). Click (); Thread.Sleep (1000); Waituntilpageloadedid (IW,"Ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_lbwebtemplate");Selector= IW. Findelement (By.id ("ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_lbwebtemplate")); select = new SelectElement (selector); Select. Selectbytext ("Records Center");Break;Case"Holdcenter": IW. Findelement (By.id ("Ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_tabid1")). Click (); Thread.Sleep (1000); Waituntilpageloadedid (IW,"Ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_lbwebtemplate");Selector= IW. Findelement (By.id ("ctl00_placeholdermain_inputformtemplatepickercontrol_ctl00_ctl01_lbwebtemplate")); select = new SelectElement (selector); Select. Selectbytext ("In-place hold Policy Center");break;} iw. Findelement (By.id ("ctl00_placeholdermain_idprimaryadministratorsection_ctl01_pickerowner_upleveldiv ")). SendKeys (@ "userName"); Iw. Findelement (By.id ("ctl00_placeholdermain_ctl02_rptcontrols_btncreatesite")). Click (); return IW;}              

corresponding to the operation on the page, the code for the first gray section selects the following tags:

The second section of the gray Section code selects the following labels:

Summary of positioning methods of select-option tags in C # selenium

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.