I have written code like this
package testpk;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.List;
import org.openqa.selenium.*;
public class Form {
public static void main(String[] args) throws InterruptedException {
// declaration and instantiation of objects/variables
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://beta-app.1bridge.in/#/auth/login");
Thread.sleep(6000);
driver.findElement(By.xpath("//input[@type='text']")).sendKeys("bbbb",Keys.ENTER);
Thread.sleep(3000);
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("123",Keys.ENTER);
Thread.sleep(7000);
driver.findElement(By.xpath("//*[@data-id='dashboard']")).click();
Thread.sleep(5000);
WebElement table = driver.findElement(By.xpath("#pcoded > div.pcoded-container.navbar-wrapper > div > div > div > div > div > div > app-default > div > app-modal-basic > div > div > div > div > div > div > table > tbody > tr:nth-child(1) > td:nth-child(2)"));
int intColValue=0;
int sum=0;
String strColValue;
//Loop through all the rows
for(int i=0;i<rows.size();i++)
{
//Get the columns in particular row
List<WebElement> cols = rows.get(i).findElements(By.tagName("td"));
//Here I am assuming values are 'String' type
//Also, I have hard-corded the column number (which you should not do and use column name as input)
strColValue = cols.get(2).getText();
//And convert those to 'Integer'
intColValue = Integer.parseInt(strColValue);
//Get the sum
sum = sum+intColValue;
}
System.out.println("Sum: "+sum);
}
}
It showing error like this Exception in thread "main" java.lang.Error: Unresolved compilation problems
:
rows cannot be resolved rows cannot be resolved
at testpk.Form.main(Form.java:38)
I want to add those row elements can anyone please guide me
driver.findElement(By.xpath("#pcoded > div.pcoded-container.navbar-wrapper > div > div > div > div > div > div > app-default > div > app-modal-basic > div > div > div > div > div > div > table > tbody > tr:nth-child(1) > td:nth-child(2)"));
you are trying to look up element using xPath locator but provide css locator.rows
is because the code doesn't ever create or set a variable namedrows
that it can see.