GWT extract all value from a row in a flextable - java

i have a flextable with many row and 5 colums, i need to extract all value from a specific row when i select one. The value must appears on a window. How can i do?

You can get access to contents of any table td element using the code below:
flexTable.getFlexCellFormatter().getElement(row, column).getInnerHTML()

If you know the row number ,you can get each element by using
flexTable.getWidget(rowNum,colNum ).getelement().getInnerHtml();//will give with html tags
You can iterate throughout the flex table also like below .
Iterator<Widget> widgetiterator = flexTable.iterator();
while (widgetiterator.hasNext()){
Widget childWidget = widgetiterator.next();
if (childWidget instanceof RadioButton) { //Example
((RadioButton) childWidget).getValue();
}
}
And
Widget w flexTable.getWidget(rowNum,colNum );
if (w instanceof TextBox) {
//TO Do get value

Related

skipping first row of a html table Java

I am still learning xpath and I am trying to skip the first row of a table because the first row has no values. I am not having success i searched through stack over flow and could not find anyone with a similar issue. My code is below:
int reqIndex = 0;
do {
List<WebElement> payDates = driver.findElements(By.xpath("//tr[starts-with(#id,'changeStartWeekGrid_row_')]/td[contains(#id,'_cell_4')/span]"));
System.out.println(payDates);
for(WebElement pd:payDates) {
LocalDate localDate = LocalDate.now();
java.util.Date d = new SimpleDateFormat("yyyy-MM-dd").parse(localDate.toString());
String str = pd.getText();
if ( str >= (d) ){ // still figuring this out
driver.findElement(By.xpath( "//tr[#id='changeStartWeekGrid_row_'" + reqIndex +"])/TBODY[#id='changeStartWeekGrid_rows_tbody']/TR[7]/TD[1]/DIV[1]/DIV[1]/DIV[1]")).click();
break;
}else{
reqIndex++;
}
}
}while(reqIndex < 7 ); /// do this 7 times
Thread.sleep(10000);
This is the part i am trouble shooting right now
List<WebElement> payDates = driver.findElements(By.xpath("//tr[starts-with(#id,'changeStartWeekGrid_row_')]/td[contains(#id,'_cell_4')/span]"));
System.out.println(payDates);
Thread.sleep(10000);
The xpath works the problem is that it is selecting the first row and it has no values row zero does so it needs to skip the first row and go to row zero.
when i run the code i get this message:
( //tr[starts-with(#id,'changeStartWeekGrid_row_')]/td[contains(#id,'_cell_4')/span])
ilter expression must evaluate to nodeset.
the row highlighted is the row i am trying to skip
cell 4 image
-----radio button html code below
<div id="changeStartWeekGrid.store.rows[5].cells[0]_widget" tabindex="0" class="revitRadioButton dijitRadio" onfocus="var registry = require('dijit/registry'); registry.byId('changeStartWeekGrid').changeActiveCell('changeStartWeekGrid_row_5_cell_0', event);" onblur="var registry = require('dijit/registry'); registry.byId('changeStartWeekGrid').blurActiveCell('changeStartWeekGrid.store.rows[5]', 'changeStartWeekGrid.store.rows[5].cells[0]');"><div class="revitRadioButtonIcon"></div></div>
---radio button picture
Try to use XPath
//table[#id='changeStartWeekGrid_rows_table']//tr[preceding-sibling::tr]
to select all tr nodes except the firts one
You can also use position() as below:
//table[#id='changeStartWeekGrid_rows_table']//tr[position()>1]
Note that in XPath indexation starts from 1 and so [position()>1] predicate means return all sibling nodes skiping the first one
You may also use
//tr[starts-with(#id,'changeStartWeekGrid_row_') and not(starts-with(#id, 'changeStartWeekGrid_row_column'))]/td[5]/span

Unable to click or select the value which is displayed in dropdown

I am trying to implement some code using Selenium Webdriver using Java.
Basically, I have a website with a text box. Once user enter the first letter, based on that a value will be displayed(using AJAX). I need to select the particular value, which i mentioned in send keys .
WebElement fromCity = driver.findElement(By.id("pickUpLocation"));
fromCity.sendKeys("A Ma Temple / 媽閣");
Thread.sleep(2000);
WebElement ajaxContainer1 = driver.findElement(By.className("txt-box ng-touched ng-dirty ng-valid"));
WebElement ajaxHolder1 = ajaxContainer1.findElement(By.tagName("ul"));
List<WebElement> ajaxValues1 = ajaxHolder1.findElements(By.tagName("li"));
for (WebElement value1 : ajaxValues1) {
if (value1.getText().equals("A Ma Temple ")) {
((WebElement)ajaxValues1).click();
break;
}
}
After you send keys.your Ajax value should be retrieved in a box related to you keyword search.You need to get the complete box.and fetch each one as you have done in for loop .get the text and compare it with your expected text and click where this condition is true.
What is that line for before thread.sleep()
I think u can try selecting through index. It should be like this
List<WebElement> ajaxValues1 = ajaxHolder1.findElements(By.tagName("li"));
Select dropdown= new Select(ajaxValues1);
dropdown.selectByIndex(0);
dropdown.selectByIndex(1);
dropdown.selectByIndex(2);
0 represents the first element in the dropdown. Based on index number of that element, feed the corresponding number in selectByIndex(0)
Let me know if this helps. Thanks

Select a particular value from the data grid that is pulled dynamically

I am trying to find a particular "Incident Number" from the table that is visible in the data grid that is generated dynamically. How can I access this?
Attached is the table view of the page from where I'm trying to see if the Incident number is present in the table or not.
Here is the html code, where I'm trying to access verify if the highlighted Incident number is present in this page or not,
We have to iterate through the data grid rows to find out the Incident Number expected i.e INC000006300863. Once we find out the incident number, we will store the row number and click on the check-box present on the same row. Coding will look like something below:
String xpath_rows = "//div[#class='ngCanvas']//div[contains(#class, 'Row')]";
String expectedIncidentNumber = "INC000006300863";
int numberOfRows = driver.findElements(By.xpath(xpath_rows)).size();
int matchedRow;
// Find out row number for **INC000006300863** incident number
for(int i=1; i<=numberOfRows; i++)
{
if(driver.findElement(By.xpath(xpath_rows +"[" +i +"]//a[contains(text(), 'INC')]")).getText().equals(expectedIncidentNumber))
{
matchedRow = i;
break;
}
}
// Click on the checkbox present on the matched row
driver.findElement(By.xpath(xpath_rows +"[" +i +"]//input[#type='checkbox']")).click();
Hope it helps!

JQuery Fetching the cell of the last row of a table and can we use autocomplete to hide some value in it

My first query,
my code goes like this
suppose a table with 5 rows and id = "mytable" and 3 cells in it
$("#mytable tbody tr:last td").each(function(i, td){
alert("value "+ " "+i+" "+td);
});
now alert results are
i will iterate from 0 to 3 and td will be [object HTMLTableCellElement]
Now i want the value inside the td
i tried td.html() but jquery says td.html() is not a function
My second query is regarding autocomplete
I have a non primary key autocomplete and on the basis of selection i have to fill in data.
Is there any way i can hide a primary key along with the autocomplete so that when user select from autocomplete a non primary key value, i can get the primary key hidden field and fetch other data regarding that value.
My code for this goes something like this
I have tried this code in this i'm putting the primary key inside the square brackets [] then splitting it and on basis of primary key m filling the data but is there any way i can hide the primary key totally. I mean like on mouse hover user will be displayed that part rather than inside autocomplete list.
e.g. abc [123]
abc [345]
here abc is the actual autocomplete values n i want to hide the primary key part which distinguishes them rather than displaying them in square brackets.
$("#myTextBox").autocomplete({source: myListItems,
change : function(event, ui) {
var value = $("#myTextBox").val();
var splitValues = value.split('[');
var last = splitValues[1].lastIndexOf(']');
var tail = splitValues[1].substring(0,last);
$("#myTextBox").val(splitValues[0]);
populateOtherFields(response, tail);
},
select : function(event, ui) {
var value = ui.item.value;
var splitValues = value.split('[');
var last = splitValues[1].lastIndexOf(']');
var tail = splitValues[1].substring(0,last);
$("#myTextBox").val(splitValues[0]);
populateOtherFields(response, tail);
}
});
function populateOtherFields(response, tail){
// code for populating other fields
}
One more thing i want to add is that on selecting the item from autocomplete it still displays the complete string with square brackets and only after hitting tab button it removes the square brackets value. Can anyone tell what am i missing or suggest any other way of doing it.
Any help will be appreciated.
to fetch cellof last row in table
// first count total tr
var i=$("#mytable tbody tr").length;
//then select last tr's all td
var lastRowTds=$("#mytable tbody tr").eq(i).('td');
try something like this:
$('#mytable').find('tr:last td').each(function() {
alert($(this).html());
});

Preserve selected model row in sorted JTable across model update

I'm having difficulties getting the following code to preserve the logically selected row in the model if the JTable has been sorted.
It works as intended when no sorting is applied.
private void updateAccountTable() {
accountsTable = guiFrame.getAccountsTable();
// Preserve selected model row
String accountNumber = "";
int selectedRow = accountsTable.getSelectedRow();
if(selectedRow >= 0){
accountNumber = (String)accountsTable.getValueAt(selectedRow, 0);
}
// Preserve sort order
// Keep eclipse happy. better way??
List <? extends SortKey> keys = accountsTable.getRowSorter().getSortKeys();
// Update displayed accounts
DefaultTableModel model = (DefaultTableModel) accountsTable.getModel();
model.getDataVector().clear();
Object[][] tableContents = accountList.getAccountsAsArray(true);
model.setDataVector(tableContents, tableHeaders);
model.fireTableDataChanged();
// reset sort order
accountsTable.getRowSorter().setSortKeys(keys);
// If updated model contains previously selected account, reselect
if (!accountNumber.equals("") && null != accountList.getAccount(accountNumber)){
for (int row=0; row<accountsTable.getRowCount(); row++){
String an = (String)accountsTable.getValueAt(row, 0);
if (an.equalsIgnoreCase(accountNumber)){
accountsTable.setRowSelectionInterval(row, row);
break;
}
}
}
else {
accountsTable.clearSelection();
}
}
Unfortunately setRowSelectionInterval() doesn't updated the selected row as expected, despite being called with the correct view row number. It seems to do nothing.
.....So,
Why is setRowSelectionInterval() failing to updated the selection, or what have I missed?
The row obtained from getSelectedRow() is in view coordinates, while the model coordinates have been changed by the intervening update. Quoting from the relevant tutorial section:
This distinction does not matter unless your viewed data has been rearranged by sorting, filtering, or user manipulation of columns.
You will need to use the conversion methods described near the end of Sorting and Filtering, which suggests:
When using a sorter, always remember to translate cell coordinates.
When you click on Jtable header to sort it, and click on a row (ex. 3rd row), you will get the value of unsorted JTable's row. To avoid this situation, use this LOC.(ik this is irrelvant to what you're trying to do but for others w/ similar problems)
int row = tblUser.getSelectedRow();
//Without below line, the value you get would be the row before sorting
int correctModel = tblUser.convertRowIndexToModel(row);
//Get username and use it to find its corresponding tuple
String username = (tblUser.getModel().getValueAt(correctModel, 1)).toString();
My table looks like this and Im trying to get the username of the selected row and w/o the 2nd LOC, I'd get the unsorted JTable's row value even after sorting it:
---------------------
| id | username |
---------------------
| | |

Categories