How do i display specific column values on console? - selenium

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");
}

Related

Dynamic Web table multiple checkbox selection for matching column value

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();
}
}

Large 2D Array Always Returns Undefined

I have a 2D array that absolutely will not return the values I need. I start off with this array:
var userdata:Array = new Array(new Array(1000),new Array(4))
Then I try to set all values to 0, with this:
this.onLoad()
{
for (i = 0; i < 1000; i++)
{
for (j = 0; j < 4; j++)
{
userdata[i][j] = 0
trace(userdata[i][j])
}
}
}
This trace returns 8 0s and then a giant amount of "undefined"s. I can't figure out why this would be. I try something like this as well:
userdata[5][0] = 0
trace(userdata[5][0])
It still returns "undefined". Can anyone help with this?
To understand why you got only 8 "zeros" and many undefined values, let's start by your array declaration :
var userdata:Array = new Array(new Array(1000),new Array(4));
Here you should understand that you have created an array with only 2 cells ( that's why userdata[5][0] is undefined ) : the 1st cell is an array of 1000 elements and the 2nd one is an array of 4 elements, and that's why you can only set 8 items ( 2 x 4 ) : the 4th first items from the 1000 of the the 1st cell + the the 4th first items from the 4 of the 2nd cell.
Let's return to your question, you want create a multidimensional array of 1000 rows and 4 columns. To start, we create an array of 1000 rows (cells) :
var a:Array = [1000]; // you can write it : new Array(1000);
Then, we create 4 columns for every row, and set values like this :
var i:Number, j:Number;
for (i = 0; i < 1000; i++)
{
// create the 4 columns
a[i] = [4]; // you can write it : a[i] = new Array(4);
for (j = 0; j < 4; j++)
{
a[i][j] = 0;
}
}
Then we can verify our array :
trace(a[0][0]); // gives : 0
trace(a[255][2]); // gives : 0
trace(a[255][5]); // gives : undefined, because we have only 4 columns
trace(a[1500][0]); // gives : undefined, because we have only 1000 rows
Hope that can help.

controlP5: matrix/ 2D array for multiple RadioButton results

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.

Selenium Help-To pass value in by.cssSelector

I am trying to import data driven framework in the selenium webdriver.
string passValue;
passValue = xlData[row][col];
for (int row = 1; row < xlData.length; row++) {
for(int col = 0; col < xlData[0].length; col++) {
wt.until(ExpectedConditions.elementsTobeclickable(By.cssSelectors("option[value=passValue]"))).click();
//How To pass value in above line of code?
}
}
//same question for the xpath as well
is this what you mean:
Take the variable and insert it into the css? or xpath? etc
wt.until(ExpectedConditions.elementsTobeclickable(By.cssSelectors("option[value=" + passValue + "]"))).click();

PostgreSQL selecting each row from two temporary tables and comparing their values

I have two tables, foo and bar that both have the same schema and rowtype
Table1
name varchar
id int
age int
Foo contains 300 records, and Bar contains 100 records. Is there a select statement that will let me compare every row in Foo with every row in bar to determine if foo.age > bar.age? So if it was a for loop in java it would look something like this:
for(int i = 0; i < Foo.length; i++){
for(int j = 0; j < Bar.length; j++){
//Select here if foo[i].age > bar[j].age
}
}
EDIT FOLLOW UP QUESTION:
If I have a temporary table called 'foobar', with the same schema as in 'Table 1' How can I insert the rows into foobar that are only part of foo into the temporary table. For example in java:
List list = new LinkedList<Table1>
for(int i = 0; i < Foo.length; i++){
for(int j = 0; j < Bar.length; j++){
if(foo[i].age > bar[j].age){
list.add(foo[i]);
}
}
}
select *
from foo
cross join bar
where foo.age > bar.age
select * from foo cross join bar where foo.age > bar.age
will do this but i wonder why do you want to compare one entry to each and every entry in other table.