我使用html单元的Java代码工作得很好,因为我需要打开一个网页并填写一个表单,最后点击提交。 但是当我尝试在Unix中部署Java代码Jar时,它无法找到并单击文本输入字段/按钮。
所以请帮忙解决这个问题。 每当我尝试通过Id获取Element时,我都会得到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
更多推荐
发布评论