I have scenario, in Excel file in first column having 3 URL. And with help of for loop i am able to launch first URL and trying to find whether single image is getting displayed or not. But in first attempt my assertion is getting failed and getting message as
": no such element: Unable to locate element: {"method".
so here my execution getting stopped. can anyone please suggest me how i can verify whether image is pass or fail for 3 URL . and how i can know for which page image is not present on page.
My code as below :-
package homework;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class NewTrialTranslationApiNew {
WebDriver driver;
@BeforeMethod
public void setup() {
System.setProperty("webdriver.chrome.driver",
"C://Users//amittu//Downloads//chromedriver_win32//chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testpages() throws Exception {
File src1 = new File(
"C://Users//amittu//Desktop//Translatelivelocales.xlsx");
FileInputStream fis = new FileInputStream(src1);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(0);
int rowcount = sheet1.getLastRowNum();
System.out.println(rowcount);
for (int i = 0; i <= rowcount; i++) {
String URLofPage = sheet1.getRow(i).getCell(0).getStringCellValue();
System.out.println("Value from excel with for loop is " + URLofPage);
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(URLofPage);
Boolean b = driver.findElement(
By.xpath("//img[@alt='Translation API']")).isDisplayed();
SoftAssert softAssertion = new SoftAssert();
softAssertion.assertTrue(b);
}
}
@AfterMethod
public void closebrowser(){
driver.quit();
}
}