BCR
BCR

Reputation: 61

How to get value from the table?

<table id="usersForm:mainTable:n" class="extdt-table-layout res-table" cellspacing="0" cellpadding="0" border="0" width="100%;" style="">
   <colgroup id="usersForm:mainTable:colgroup:body">
      <tbody id="usersForm:mainTable:tb">
         <tr id="usersForm:mainTable:n:0" class="extdt-firstrow rich-extdt-firstrow extdt-row-selected rich-sdt-row-selected res-table-selected" onmousedown="handleMouseClick(event)">
            <td id="usersForm:mainTable:1:name" class="extdt-cell rich-extdt-cell">
               <div class="extdt-cell-div">
                  <div onmouseup="if (showMenu(this)) {document.lkjasdf = event; selectContextMenu('ENTTUSER','MbUsersSearch');}">
                     <span title="ADMIN" onmouseup="if(!rightButton && isSelectedRow(this,rightButton) && false && !disableContext) {setDisableContext(true); beforePrepareDefaultAction('ENTTUSER','MbUsersSearch');}">ADMIN</span>

Using htmlelements pattern, i want get value from table, ie verify that table contains value "ADMIN". In htmlelements can able work with tables "from the box". I wrote:

import ru.yandex.qatools.htmlelements.element.Table;
public class MainTableForm extends HtmlElement {
    @FindBy(id = "usersForm:mainTable:n")
    private Table table;
}

Then I do not know which method helps to get the value.

Upvotes: 3

Views: 821

Answers (3)

artkoshelev
artkoshelev

Reputation: 892

You can use List<List<String>> getRowsAsString() method to get all the values from your table. Then just check this collection with hamcrest matcher. So the final code will be pretty simple:

assertThat(table.getRowsAsString(), contains(contains(equalTo("ADMIN"))));

Upvotes: 1

Vaibhav
Vaibhav

Reputation: 2556

Try to find out by installing firepath find out the path by firepath

Upvotes: 0

JeffC
JeffC

Reputation: 25611

You can do this

WebElement adminSpan = driver.findElement(By.cssSelector("#usersForm:mainTable:n span[title='ADMIN']"));
System.out.println(adminSpan.getText().trim());

I added the TABLE id just in case there is more than one of these admin SPANs. The CSS selector reads as find an element with an id (#) of usersForm:mainTable:n that has a descendant () SPAN with the title of ADMIN.

You may or may not need to trim(). I've gotten to the point where I just always trim() because it's easy and it saves me time finding and adding it later when I find out I needed it but didn't realize it. :)

Upvotes: 0

Related Questions