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