为什么我使用 HtmlUnitDriver 会收到 UnknownHostException?
我正在编写一个测试,应该只从重定向中获取 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是部分 url_string
bank.test.com
您需要将完整的(完全合格) url_string 作为以下内容:Instead of the partial url_string
bank.test.com
you need to pass the complete (fully qualified) url_string as follows:通常指出将URL分解到IP地址的某些问题。
请检查此URL是否可从您的浏览器可用。也许为您的浏览器配置了代理。
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.