Selenium Webdriver w/Java: locating elements with multiple class names with one command -


i'm trying use selenium (2.31.0, using javase 1.6 , ie9) find series of elements on page. these elements have 1 of 2 class names, 'datalabel' or 'datalabelwide'. currently, code collects these elements in 2 separate arraylists, 1 each class name, converts them arrays , combines them 1 array. method, however, lists elements out of order, , need them left in same order they're found in page's html source.

the above-mentioned section of code looks (with comments added explanation):

// application runs on webdriver d, internetexplorerdriver. // after navigating page in question...  list<webelement> labels = d.findelements(by.classname("datalabel")); list<webelement> wlabels = d.findelements(by.classname("datalabelwide")); // locates elements of either type respective class name.  webelement[] labelsarray = labels.toarray(new webelement[labels.size()]); webelement[] wlabelsarray = wlabels.toarray(new webelement[wlabels.size()]); // converts each arraylist array.  list<webelement> alllabels = new arraylist<webelement>(); // creates arraylist hold elements both arrays.  for(int = 0; < labelsarray.length; a++) {     alllabels.add(labelsarray[a]); } for(int b = 0; b < wlabelsarray.length; b++) {     alllabels.add(wlabelsarray[b]); } // adds elements of both arrays unified arraylist, 1 one.  webelement[] alllabelsarray = alllabels.toarray(new webelement[alllabels.size()]); // converts unified arraylist array usable test purposes. // far complicated (obviously), , elements end out-of-order in array. 

i think efficient solution locate elements either class name they'd included in single list/array right away. i've done searching on own, haven't found conclusive ideas on how might manage task. if there way this, please tell me it.

why wouldn't following:

driver.findelement(by.cssselector(".datalabel,.datalabelwide"); 

the '.' selector says, "give me elements class." ',' operator css selector 'or' operator.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -