【问题标题】:Edureka - Handle exceptions in Selenium Web Driver - no print outEdureka - 在 Selenium Web 驱动程序中处理异常 - 没有打印输出
【发布时间】:2021-04-05 09:38:37
【问题描述】:

我是自动化测试的菜鸟,我正在尝试通过 Youtube 学习如何做到这一点。

https://youtu.be/FRn5J31eAMw?t=12405

在 Edureka 的这门课程中,有一个示例,他们试图处理异常,在他们运行脚本后,系统会在控制台中向他们显示一条我无法获取的消息。

package co.edureka.selenium.demo;


import java.util.NoSuchElementException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class HandlingExceptions {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        Thread.sleep(3000);
        
        try {
            driver.findElement(By.name("fake")).click();    
            
        }catch (NoSuchElementException e) {
            
            System.out.println("element is not found");
            System.out.println("Hello");
            
            //throw(e);
        }
        System.out.println("Hello");
    }

}

这是他们正在运行的 Java 脚本,最后在控制台中他们得到了这个结果 Edureka Console

但我得到的东西完全不同,即使我的代码完全相同。

My Console

我做错了什么?

【问题讨论】:

  • 在异常块中添加System.out.println(e);

标签: java eclipse selenium-webdriver exception selenium-chromedriver


【解决方案1】:

您正在使用“import java.util.NoSuchElementException; " 在文件的顶部,所以请删除并使用下面的一个

org.openqa.selenium.NoSuchElementException

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多