尝试通过unix服务器使用HTML单元(Trying to use HTML Unit through unix server)

编程入门 行业动态 更新时间:2024-10-25 00:28:03
尝试通过unix服务器使用HTML单元(Trying to use HTML Unit through unix server)

我使用html单元的Java代码工作得很好,因为我需要打开一个网页并填写一个表单,最后点击提交。 但是当我尝试在Unix中部署Java代码Jar时,它无法找到并单击文本输入字段/按钮。

所以请帮忙解决这个问题。 每当我尝试通过Id获取El​​ement时,我都会得到Null指针异常,例如:

1)HtmlAnchor addr =(HtmlAnchor)page.getElementById(“element_id”);

2)page = addr.click();

在第2行获得错误

我只是将类导出为Runnable Jar文件并在unix java -jar上运行它

请帮忙。

My Java code using html unit is working perfectly fine as I need to open a webpage and fill a form and finally click submit. But when I tried to deploy Java code Jar in Unix, it's unable to find and click on the text input fields/buttons.

So please help regarding this. I am getting a Null Pointer Exception whenever i am trying to fetch an Element by Id,for example :

1) HtmlAnchor addr = (HtmlAnchor) page.getElementById("element_id");

2) page = addr.click();

Getting an error at line 2

I am just export the class as Runnable Jar file and running it on unix java -jar

Please help.

最满意答案

通常,您可以打印page.asXml()以查看页面的显示方式。

从服务器和计算机运行之间可能存在网络连接差异。 主机名与'localhost'也会造成一些差异。

等待后台线程可能因机器而异,请阅读此内容 。

另外,请使用最新版本的HtmlUnit,您可以打印使用过的版本 。

希望有所帮助

Usually, you could print page.asXml() to see how the page is seen.

You could have network connectivity difference, between running from the server and from your machine. Hostname vs 'localhost' can cause some differences too.

Waiting for background threads can differ between machines, please read this.

Also, please use latest version of HtmlUnit, you can print the used version.

Hope that helps

更多推荐

本文发布于:2023-08-07 08:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463809.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元   服务器   unix   HTML   server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!