Finding the element in DropDown in C# (Selenium) -


i trying find field name "userpick", , select first item drop down list.

the html code behind this:

<div class="fullrow"> <label for="userpick" class="fieldlabel90right">user:</label> <select id="userpick" name="userpick" class="selectfont" size="1"   onchange="editibuser(this)"> <option value="0">--- select user edit ---</option> <option value="1623" size="small" selected="">iiii, ooooo  (ioop78 - email: jjj@ff.com)</option> <option value="1620" size="small">jjj, aku  (aroy - email: lll@hh.com)</option> <option value="1625" size="small">lll, kk  (lll90 - email: kl@h.com) </option> <option value="1626" size="small">roy, adrija  (ar8456 - email: rry@gm.com) </option> </select> <input type="button" value="sort email address" name="btnsort"  onclick="usersort('name')" style="width: 180px; line-height: 1px;"/> </div> 

the c# code using is:

var user = driver.instance.findelement(by.id("userpick")); var firstitem1 = driver.instance.findelements(by.tagname("option"))[1]; firstitem1.click(); 

i have used:

var wait = new webdriverwait(driver.instance, timespan.fromseconds(20)); user=wait.until(expectedconditions.elementisvisible(by.id("userpick"))); var firstitem1 = driver.instance.findelements(by.tagname("option"))[1]; firstitem1.click(); 

and well:

var user = driver.instance.findelement(by.id("userpick")); var firstitem1 = driver.instance.findelements(by.tagname("option"))[1]; ijavascriptexecutor js1 = driver.instance ijavascriptexecutor; js1.executescript("arguments[0].click()", firstitem1); 

the problem facing is, not giving exception , overlooking field name , giving me successful test.

i need find field name userpick, seems unable find that. can please help?

you should try using selectelement dropdown below :-

var wait = new webdriverwait(driver.instance, timespan.fromseconds(20)); var user=wait.until(expectedconditions.elementisvisible(by.id("userpick"))); var select = new selectelement(user); select.selectbyindex(1); 

or

 select.selectbyvalue("1623"); 

hope helps...:)


Comments