My following code displays all the column values of a particular row successfully but the value of column 3 is printing twice, how do i solve? And there are total 10 columns and i want to print/display the values of the column 1,3 and 7 only.
What changes need to be done in the following code?
int rows_count = patientList.size();
for (int row=0; row< rows_count; row++)
{
List<WebElement> Columns_rows = patientList.get(row).findElements(By.tagName("div"));
int columns_count = Columns_rows.size();
for (int column=0; column < columns_count; column++)
{
String celtext = Columns_rows.get(column).getText();
System.out.format("%16s", celltext);
}System.out.println("\n");
}
Option 1
To find the 3,5 and 7th cell data you should use xpath of that columns
to locate it. for example:
dynamicxpath_7col=//*[#id='tableid']/table/tbody/tr[Columns_rows]//use variable for each row
Webelement 7thcolumn=Columns_rows.findelement(By.xpath("dynamicxpath"));
Option 2
int rows_count = patientList.size();
for (int row=0; row< rows_count; row++)
{
List<WebElement> Columns_rows = patientList.get(row).findElements(By.tagName("div"));
int columns_count = Columns_rows.size();
for (int column=0; column < columns_count; column++)
{
String celtext = Columns_rows.get(column).getText();
if(column==1 or column==5 or column==7)
System.out.format("%16s", celltext);
}System.out.println("\n");
}
I have application where there is a dynamic web table, I want to select multiple check box for matching value in one of column.
Refer attached image:
Here is what I've tried so far:
List<WebElement> Rows = s.findElements((By.xpath("//a[text()='Nitesh Kumar']")));
System.out.println("No of rows = "+Rows.size());
int z=Rows.size();
int i =0; for(i=0;i<z;i++)
{
for (int j = 0; j < Rows.size(); j++ )
{
s.findElement(By.xpath("//a[text()='Nitesh Kumar']/../../td[1]")).click();
}
}
Change the xpath to
//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]
to find the elements from the table.
Once the elements are found get the size of the list and use the below xpath to click the check box
//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]../td[1]
The complete code would be something like below.
List<WebElement> Rows = s.findElements((By.xpath("//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]")));
System.out.println("No of rows = "+Rows.size());
int z=Rows.size();
int i =0;
for(i=0;i<z;i++)
{
for (int j = 0; j < Rows.size(); j++ )
{
s.findElement(By.xpath("//table[#id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]../td[1]")).click();
}
}
I'm trying to query a user to select from 4 or more sets of radio buttons where there are 5 buttons in each set (Processing 2+). Where I'm having trouble is taking the array created by selecting from each set of buttons and getting it to fill columns in a matrix where the elements can be queried and the 2D array can be printed and ultimately written as csv or tab txt file.
import controlP5.*;
ControlP5 controlP5;
RadioButton c0;
RadioButton c1;
RadioButton c2;
RadioButton c3;
int cols = 5;
int rows = 4;
int[][] myArray = new int[cols][rows];
void setup() {
size(600,650);
controlP5 = new ControlP5(this);
c0 = controlP5.addRadioButton("ch0",60,60)
.setSize(20,20)
.setItemsPerRow(5)
.setSpacingColumn(50)
.addItem("c03", 1)
.addItem("c04", 2)
.addItem("c05", 3)
.addItem("c0AM", 4)
.addItem("c0AF", 5)
;
c1 = controlP5.addRadioButton("ch1",60,80)
.setSize(20,20)
.setItemsPerRow(5)
.setSpacingColumn(50)
.addItem("c13", 1)
.addItem("c14", 2)
.addItem("c15", 3)
.addItem("c1AM", 4)
.addItem("c1AF", 5)
;
c2 = controlP5.addRadioButton("ch2",60,100)
.setSize(20,20)
.setItemsPerRow(5)
.setSpacingColumn(50)
.addItem("c23", 1)
.addItem("c24", 2)
.addItem("c25", 3)
.addItem("c2AM", 4)
.addItem("c2AF", 5)
;
c3 = controlP5.addRadioButton("ch3",60,120)
.setSize(20,20)
.setItemsPerRow(5)
.setSpacingColumn(50)
.addItem("c33", 1)
.addItem("c34", 2)
.addItem("c35", 3)
.addItem("c3AM", 4)
.addItem("c3AF", 5)
;
}
void draw() {
background(0);
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isGroup() && theEvent.name().equals("ch0") || theEvent.name().equals("ch0") || theEvent.name().equals("ch2") || theEvent.name().equals("ch3")){
println(theEvent.name());
println(theEvent.arrayValue());
//float t=float(theEvent.arrayValue());
//int[][] = { {float getGroup(),float[] getArrayValue()}, {3,2,1,0}, {3,5,6,1}, {3,8,3,4} };
//int cols = 4;
//int rows = 5;
//int[][] myArray = new int[cols][rows];
// Two nested loops allow us to visit every spot in a 2D array.
// For every column I, visit every row J.
//for (int i = 0; i < cols; i++) {
// for (int j = 0; j < rows; j++) {
//myArray[i][j] = float(theEvent.arrayValue);
}
}
You were mixing different things together. Also you don't need to check whole array and store this information. Just update clicked button. Here is new version of your controlEvent
void controlEvent(ControlEvent theEvent) {
int cols = 4;
int rows = 5;
int[][] myArray = new int[cols][rows];
switch(theEvent.getId()){
case 0:
myArray[0][(int)theEvent.value()-1] = 1;
break;
case 1:
myArray[1][(int)theEvent.value()-1] = 1;
break;
case 2:
myArray[2][(int)theEvent.value()-1] = 1;
break;
case 3:
myArray[3][(int)theEvent.value()-1] = 1;
break;
}
println("==== " + theEvent.getId() + " ===");
println(myArray[theEvent.getId()]);
}
To do this simple switch you need to add ID parameter to all your radio buttons like this:
c3 = controlP5.addRadioButton("ch3", 60, 120)
.setId(3)
.setSize(20, 20)
...
I don't know how exactly you want use this array so my implementation use it as local variable so it will be deleted every time this event is called but this could be avoided by declaring array as global variable and then deleting only updated column.
I have some script that is delivering a series of rows from an SQL database.
I want to append.() a button to each row. My current code is:
tx.executeSql('SELECT * FROM myprogram', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
$('#myprog').append(results.rows.item(i).event)
$('.event').append('<button class="save_event">Remove</button>');
}
});
But the buttons get doubled up. For example if I get 3 rows, the first row will have 3 buttons, the 2nd will have 2 and the last will have 1 button.
Can anyone help me out to have the buttons display only once per row?
Thanks!
I found the answer, quite simple:
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
$('#myprog').append(results.rows.item(i).event).append('<button class="remove_event">Remove</button>');
}
$('#myprog').append(results.rows.item(i).event).append('<button class="remove_event">Remove</button>');
You need to append to $('#myprog') selector.
How to do linear I want to get the position for an item in the array to insert , I mean the index where I have to insert the data in the array. How can I achieve this by using Linear search only . Suggestions Please.
Linear search for example with a for loop:
int[] test = new int[1024];
// i assume you have something like this
int searchnumber = 17;
int foundindex = -1;
for(int i = 0; i < count, i++)
{
if (test[i] == 17)
{
foundindex = i;
break;
}
}
// now you have the found index in foundindex
If your array is sorted you could use a binary search, but since you asked for a linear search tghis should do the trick.
Find the nearest possible value and insert before or after it depending on your need
loop
{
int index = [arrResultRow indexOfObject:10];
[arrResultRow insertObject:object atIndex:index+1]
}