TypeError can’t access dead object geckodriver

TypeError cant access dead object geckodriver,read run selenium script using geckodriver. While working in Selenium WebDriver scripts,you can face error saying TypeError can’t access dead object in console output.It is not able to identify exactly where error is giving and why this error is coming.

ALSO READ:

Send Extent Reports in Email with Screenshots
How to write Test Cases PASS or FAIL in Excel using Selenium
How to capture screenshot for failed test cases in Selenium
Selenium Webdriver Using Python – Complete Tutorial Guide
How to get the number of Elements in a list in Python
Get HTML source of webelements using python
Print google search results using Python

ALSO READ  Selenium WebDriver Page Object Model Framework Introduction

TypeError can’t access dead object

Consider below example about switch to frames using index value and while execute the script giving TypeError can’t access dead object error message on console.

Example:

 

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.gecko.driver", "D:/NTTA_Automation/ChasePayment/driver/geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("https://xxxxx.com");
Thread.sleep(5000);
driver.switchTo().frame(0);
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("tollplus");
driver.findElement(By.id("ccNumber")).clear();
driver.findElement(By.id("ccNumber")).sendKeys("5454545454");
driver.findElement(By.id("CVV2")).clear();
driver.findElement(By.id("CVV2")).sendKeys("123");
Thread.sleep(1000);
new Select(driver.findElement(By.id("expMonth"))).selectByVisibleText("12");
Thread.sleep(1000);
driver.findElement(By.id("Button")).click();
Thread.sleep(5000);

String getText = driver.findElement(By.xpath("//h2[text()='Success']")).getText();

if (getText.equals("Success")) {
system.out.println("Message Success is displaying on screen");

driver.quit();
} else {
System.out.println("Message Success is not displaying on screen");
driver.quit();
}

}
}

Run as Java Application and you will get TypeError can’t access dead object error message on console,so i’ve found solution for this type or Type of errors.

ALSO READ  How To write Test Case is PASS or FAIL using Selenium

Solution : TypeError can’t access dead object

After switching into “driver.switchTo().frame(0)”; any frame ,we need to come back to default content of our respective open browser page,add below line before getText method as below.

 

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.gecko.driver", "D:/NTTA_Automation/ChasePayment/driver/geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("https://xxxxx.com");
Thread.sleep(5000);
driver.switchTo().frame(0);
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("tollplus");
driver.findElement(By.id("ccNumber")).clear();
driver.findElement(By.id("ccNumber")).sendKeys("5454545454");
driver.findElement(By.id("CVV2")).clear();
driver.findElement(By.id("CVV2")).sendKeys("123");
Thread.sleep(1000);
new Select(driver.findElement(By.id("expMonth"))).selectByVisibleText("12");
Thread.sleep(1000);
driver.findElement(By.id("Button")).click();
Thread.sleep(5000);

//Add below line to switch back to default content to get access to all the objects.
driver.switchTo.defaultContent();

String getText = driver.findElement(By.xpath("//h2[text()='Success']")).getText();

if (getText.equals("Success")) {
system.out.println("Message Success is displaying on screen");

driver.quit();
} else {
System.out.println("Message Success is not displaying on screen");
driver.quit();
}

}
}

 

Rajesh

Rajesh has over 8+ years of experience in Quality Assurance (Automation/ Manual). I've completed his B.Texh. He is an experienced software tester,work experience include working on tools like TestNG, Sikuli, Autoit, Selenium Builder and Appium. Abhishek has worked on various projects from verticals like Retail, Health Insurance, tolling and many more and passionate about designing Automation Frameworks that are effective and easy to maintain using Selenium Java.

Leave a Reply

Your email address will not be published. Required fields are marked *