Fetching the column values inside the grid - selenium

In my table, having 5 row 4 columns, I want to fetch only 3 rd column data values present in all the rows.
Can anyone give me a code template to achieve this task?

your code will be something like:
List<String> values = new List<String>();
int row =5;
for (int i=1; i<=row; i++)
{
values.add(driver.Find(By.XPath(".//table/tbody/tr[" + i + "]/td[3]").Text) ;
}

Related

DART SQL How do I read multiple row values (with multiple columns) from SQL query results in Dart?

Right now i am able to read data from the column in the single returned row ad below
var resultsDoc = await conn
.query('select fNAME, SPECIALITY, CATENAME from doctor where id = ?', [5]);
for (var rowDoc in resultsDoc) {
ffname = rowDoc[0]; //reading value at column 1
sspeciality = rowDoc[1]; //reading value at column 2
ccategory = rowDoc[2]; //reading value at column 3
}
what if i wanted to return the entire table as below
enter image description here
Team, assist on how to read those values.
Thank You
You were close!
for (var rowDoc in resultsDoc) {
print(rowDoc.join('\t'));
}
Or did you want to transpose the list of lists, so that you'd have 3 lists, one for each column?

How can select different drop down value everytime in for loop

My aim is to add the different drop down value 3 times in the script.
By using for I am able to select and add the same value 3 times but want to select and add the different drop down value every time.
Right now i am able add the same skill three times but i want to add three.
Please suggest how can different value every time the loop executes
here is the code which i am using right now.
for(int i=0; i<=2; i++){
Select skill = new Select(m1.findElement(By.xpath(".//select[#id='skill']")));
skill.selectByValue(skills);
Select proficiency = new Select(m1.findElement(By.xpath(".//select[#name='proficiency']")));
proficiency.selectByValue("3");
m1.findElement(By.xpath(".//button[#id='addskill']")).click();
Thread.sleep(2000);
If you want add diffrent dropdown value 3 times use dropdown.selectByIndex(index).
Select skill = new Select(m1.findElement(By.xpath(".//select[#id='skill']")));
Select proficiency = new Select(m1.findElement(By.xpath(".//select[#name='proficiency']")));
for(int i = 1; i <= 3; i++){
skill.selectByIndex(i);
proficiency.selectByIndex(i);
m1.findElement(By.xpath(".//button[#id='addskill']")).click();
Thread.sleep(2000);
}
OR
For random value selection in the drop down items.You need know how many items are their in the dropdown first.
Select skill = new Select(m1.findElement(By.xpath(".//select[#id='skill']")));
List<WebElement> listOptionDropdown = skill.getOptions();
int dropdownCount = listOptionDropdown.size();
Select proficiency = new Select(m1.findElement(By.xpath(".//select[#name='proficiency']")));
List<WebElement> listOptionDropdown1 = skill.getOptions();
int dropdownCount1 = listOptionDropdown1.size();
for(int i = 1; i <= 3; i++){
int random = (int)(Math.random());
random = random*dropdownCount +1;
skill.selectByIndex(random);
int random1 = (int)(Math.random());
random1 = random1*dropdownCount1 +1;
proficiency.selectByIndex(random1);
m1.findElement(By.xpath(".//button[#id='addskill']")).click();
Thread.sleep(2000);
}

how to find one element from one cell of a web table without using any locator like id,xpah,name etc. of that cell in selenium

I have one dynamic table. in row=1 and column=3 the value of the cell is 2. I don't know any xpath, id, name etc.
To use td and tr how can I get that value.
Sample table
WebElement table= driver.findElement(By.id("table"));
/* List of all rows*/
List< WebElement> rows = table.findElement(By.tagName("tr"));
int row_count = rows.size();
/*Looping rows*/
for(int i=0;i< row_count;i++)
{
/* List all columns*/
List < WebElement> columns = rows.findElement(By.tagName("td"));
int column_count= columns.size();
for(int j=0;j< column_count ; j++)
{
String celltext= columns.get(j).getText();
System.out.println(celltext); ///This will print all values inside the table.
////But I want only one value from one cell, suppose from first row and third column
}
}
As you are saying if your td cell value is 2 and no other cell has value 2 then try this xpath :-
//td[text() = '2']
or
//tr[1]/td[text() = '2']
And if you want to get cell value try as below (Amusing you are using java) :-
WebElement table= driver.findElement(By.id("table"));
String cellValue = driver.findElement(By.xpath("//table/tr[1]/td[3]")).getText()
Edited :- you should try to get text from first row third column as below :-
String thirdColumnText = table.findElement(By.tagName("tr")).get(0).findElements(By.tagName(td)).get(3).getText();
Note :- For more better solution, need to share your table HTML
hope it helps..:)

How to send specific rows of excel to data provider in testNG?

I have created an excel containing multiple rows, each row corresponding to a test case. The Excel has around 22 columns (parameters) including a "Flag" column.
I want the Dataprovider to return only those columns which has a value 'Y' in the excel column. The use case is that when the client wants to run a particular test case, they only need to flag it to Y or N. How can I achieve this is in TestNG with Selenium?
My colleague had helped me to achieve this using following code, but this does not work as per my new code structure.
#DataProvider(name = "Order")
public Object[][] menu()
{
Object[][] data = UtilLibrary.getData("Order");
int intColCount = UtilLibrary.datatable.getColumnCount("Order");
int j = 0;
int arrRowCount=0;
for (int i = 0; i < data.length; i++) {
if((data[i][intColCount-1]).equals("Y"))
{
arrRowCount++;
}
}
j=0;
Object[][] retData = new Object[arrRowCount][intColCount];
for (int i = 0; i < data.length; i++)
{
if ((data[i][intColCount-1]).equals("Y")) {
retData[j] = data[i]; j++; }
}
return retData;
}
The above code sends only the record/s having flag='Y' in the excel to the Dataprovider. But, it was working only when the test script had a single #Test method having all automation steps, while now I have multiple #Test methods to simulate the same steps to which I have passed this same Dataprovider (Order).
Let me know if someone has achieved this using a similar code or if TestNG has a specific feature to send filtered rows of excel to the Dataprovider
I have now fixed the issue. The reason why the above given code for rows having flag = 'Y' in Excel was not working with multiple #Test methods was only due to a silly mistake. The mistake was that I had changed the excel structure a bit and did not modify the above code as per the index of the new flag column.

Qliksense Extension - Select Values

I need to pass the value 'A' to be selected into a Qliksense extension. This extension contains 1 dimension and 1 measure. I would like 'A' to be selected in the 1 dimension.
It seems that self.selectValues(0, 'A', false); is the call for this. I can't get this to work at all.
How do I select 'A' in this extension or the underlying table?
Details:
I have the following code inside the paint function that renders the data (this part works):
// iterate over all rows
var hc = layout.qHyperCube;
for (var r = 0; r < hc.qDataPages[0].qMatrix.length; r++) {
table += '<tr>';
// iterate over all cells within a row
for (var c = 0; c < hc.qDataPages[0].qMatrix[r].length; c++) {
table += '<td>';
table += hc.qDataPages[0].qMatrix[r][c].qText;
table += '</td>';
}
table += '</tr>';
}
Method expects an array and the element number of the dimension value, so this should work:
self.selectValues(0, [qElemNumber], false);