how to catch PHP errors in selenium using java?

how to catch PHP errors in selenium using java? This is the link for webpage:

http://selenium.couponapitest.com/page-2.php

I am new to selenium so please help me on this.

shaifali Default Asked on June 7, 2016 in Selenium WebDriver.
Add Comment
2 Answer(s)

Shaifali, Let me get back to you on this by tonight.

Virender

Virender Singh Professor Answered on June 8, 2016.
Add Comment

Hi shaifali,

you can override on Exception method in the below link to check if the exception is caused by this error page on not

you can override method something like that

public void onException(Throwable arg0, WebDriver arg1) {
// TODO Auto-generated method stub
check the presence of error page in this
System.out.println(“Exception occured at “ + arg0.

http://toolsqa.com/selenium-webdriver/event-listener/

ankit ramola Vice Professor Answered on June 8, 2016.

Here is the example for the same
this is my base class
public class BaseClass {

public WebDriver driver;
public EventFiringWebDriver event1;
public MyWebListerners mwl;
public BaseClass() {
driver = new FirefoxDriver();
mwl = new MyWebListerners();
driver = new EventFiringWebDriver(driver).register(mwl);
}

// listener class

public class MyWebListerners implements WebDriverEventListener{

@Override
public void afterChangeValueOf(WebElement arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void afterClickOn(WebElement arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void afterFindBy(By arg0, WebElement arg1, WebDriver arg2) {
// TODO Auto-generated method stub

}

@Override
public void afterNavigateBack(WebDriver arg0) {
// TODO Auto-generated method stub

}

@Override
public void afterNavigateForward(WebDriver arg0) {
// TODO Auto-generated method stub

}

@Override
public void afterNavigateTo(String arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void afterScript(String arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void beforeChangeValueOf(WebElement arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void beforeClickOn(WebElement arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void beforeFindBy(By arg0, WebElement arg1, WebDriver arg2) {
// TODO Auto-generated method stub

}

@Override
public void beforeNavigateBack(WebDriver arg0) {
// TODO Auto-generated method stub

}

@Override
public void beforeNavigateForward(WebDriver arg0) {
// TODO Auto-generated method stub

}

@Override
public void beforeNavigateTo(String arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void beforeScript(String arg0, WebDriver arg1) {
// TODO Auto-generated method stub

}

@Override
public void onException(Throwable arg0, WebDriver arg1) {
// TODO Auto-generated method stub
System.out.println(“executed method on excepion”);
if(arg1.findElement(By.xpath(“//b[text()=’Fatal error’]”)).isDisplayed()){
Assert.assertTrue(false);
}

}

}

and here is test class

public class Test1 extends BaseClass{

@Test
public void testLis(){
driver.get(“http://selenium.couponapitest.com”);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath(“//a[text()=’Page 2′]”)).click();
driver.findElement(By.xpath(“//a[text()=’Page 3′]”)).click();
}

@AfterTest
public void teardown(){
driver.quit();
}
}

on June 8, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.