jeudi 18 juillet 2019

How can i assign if statement for error and correct class

I want IF statement to check if class name is "errorexist", if it does then it will carryout IF statement else it will carryout ELSE statement. Here i am getting error to convert webelement to boolean

Trying this in Eclipse with Java

String a ="http://www.myfortunecookie.co.uk/fortunes/";
int i;
String s;
for (i=1;i<10;i++)
{       
String b = Integer.toString(i);
s=a+b;
driver.get(s);
if (driver.findElement(By.className("errorexist")))
{
System.out.println(i);
}
else
{
System.out.println(i+" "+ driver.findElement(By.xpath("//*[@class='fortune']")).getText());
}
}

If error page appears then it will print value of i If class fortune found then it will get text of class

Aucun commentaire:

Enregistrer un commentaire