为什么我使用 HtmlUnitDriver 会收到 UnknownHostException?

发布于 2025-01-20 01:06:28 字数 685 浏览 4 评论 0原文

我正在编写一个测试,应该只从重定向中获取 URL,不需要加载不存在的页面。每次我都会遇到这个异常:

java.lang.RuntimeException: java.net.UnknownHostException: No such host is known (bank.test.com)

我说过,不需要加载我需要的只是在用户提交表单时获取URL,我应该怎么做?

这是导致异常的代码:

@Step("Sign in")
    public static String signIn(WebDriver driver, String url, String username, String password) {
        driver.get(url);

        HtmlUnitDriverSteps.setFieldValueByName(driver, USERNAME, username);
        HtmlUnitDriverSteps.setFieldValueByName(driver, PASSWORD, password + Keys.ENTER);
        
        return driver.getCurrentUrl();
    }

我的问题有解决方案吗?

I am writing a test that should get only the URL from the redirect, there is no need to load the non-existing page. Every time I get this exception:

java.lang.RuntimeException: java.net.UnknownHostException: No such host is known (bank.test.com)

How I said, there is no need to load only what I need is to get the URL when a user submits the form, how should I do it?

This is the code where it is causing exception:

@Step("Sign in")
    public static String signIn(WebDriver driver, String url, String username, String password) {
        driver.get(url);

        HtmlUnitDriverSteps.setFieldValueByName(driver, USERNAME, username);
        HtmlUnitDriverSteps.setFieldValueByName(driver, PASSWORD, password + Keys.ENTER);
        
        return driver.getCurrentUrl();
    }

Is there solution for my issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

儭儭莪哋寶赑 2025-01-27 01:06:28

而不是部分 url_string bank.test.com 您需要将完整的(完全合格) url_string 作为以下内容:

https://bank.test.com

Instead of the partial url_string bank.test.com you need to pass the complete (fully qualified) url_string as follows:

https://bank.test.com
无人问我粥可暖 2025-01-27 01:06:28

unknownnothostexception:没有知道这样的主机

通常指出将URL分解到IP地址的某些问题。
请检查此URL是否可从您的浏览器可用。也许为您的浏览器配置了代理。

UnknownHostException: No such host is known

This usually point to some problems resolving the URL into an ip address to connect to.
Please check if this url is available from your browser. Maybe there is a proxy configured for your browser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文