java - Locating data in a complex table in Selenium Webdriver -


i trying drill down on user in table full of users using selenium webdriver, have worked out how iterate through table i'm having trouble selecting person want.

here html (modified x's due not being data)

<table id="xxxxxxxxx_list" cellspacing="0" cellpadding="0" style=" border:0px black solid;width:100%;"> <tbody> <tr cellspacing="0" style="height: 16px;"> <tr> <tr onclick="widgetlistview_onclick('xxxx_list',1,this,event)"> <tr onclick="widgetlistview_onclick('xxxx_list',2,this,event)"> <tr onclick="widgetlistview_onclick('xxxx_list',3,this,event)"> <tr onclick="widgetlistview_onclick('xxxx_list',4,this,event)"> <tr onclick="widgetlistview_onclick('xxxx_list',5,this,event)"> <tr onclick="widgetlistview_onclick('xxxx_list',6,this,event)"> <tr onclick="widgetlistview_onclick('xxxx_list',7,this,event)"> <td class="listview_default_datastyle" nowrap="" style="font-size:12px ; font-family: sans-serif ;color: black ;background: #ffffff "  ondblclick="xxxxlistview_ondblclick('xxxxx_list',17, event)">name</td> <td class="listview_default_datastyle" nowrap="" style="font-size:12px ;font-family: sans-serif; color: black ;background: #ffffff " ondblclick="xxxxx_ondblclick('xxxx_list',17, event)"> </td> </tr> 

here code writing try , find user going name in table.

webelement table = driver.findelement(by.id("table_list"));      // tr elements table     list<webelement> allrows = table.findelements(by.tagname("tr"));     // , iterate on them, getting cells     (webelement row : allrows) {      list<webelement> cells = row.findelements(by.tagname("td"));      (webelement cell : cells) {                  list<webelement> names = cell.findelements(by.xpath("//td[text()='name']"));         system.out.println(names); 

this prints thousands of [] (the table huge in real application). need stop when find correct name , create web element out of table row. can click , drill down on.

sorry if of bit vague,

well if each name in table unique, don't need complicate things much. search element text matching 'name' select row accordingly. @ code below:

webelement name = driver.findelement(by.xpath("//table[@id='xxxxxxxxx_list']//td[contains(text(),'name')]"));//select td text name in table id xxxxxxxxx_list webelement rowwithname = name.findelement(by.xpath("./.."));//select parent node, i.e., tr, of td text name /*  * row other element or perform action on row.  */ 

if names not unique, i.e., same name exists twice @ similar node, 1st instance picked each time. in case have try things differently, i.e., have index xpath correct instance of matching name. ask if have further doubts :)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -