简体   繁体   English

模拟 Java 中 JavaScript function 的点击

[英]Simulate a click on JavaScript function in Java

I'm writing a program that interacts with a website automatically in Java.我正在编写一个与 Java 中的网站自动交互的程序。 I figured out how to build and send GET/POST requests to simulate a click or form submit.我想出了如何构建和发送 GET/POST 请求来模拟点击或表单提交。 But I encountered a link that runs a JavaScript function.但是我遇到了一个运行 JavaScript function 的链接。

<a href="javascript:function()">Run</a>
function function()
{
    document.myform.submit();
}

After clicking, the webpage is redirected to another URL.点击后,网页重定向到另一个URL。 How do I simulate this behavior in Java?如何在 Java 中模拟这种行为?

I've always had the best luck with HTMLUnit.我一直对 HTMLUnit 抱有最好的运气。 It uses apache http and handles all the interaction pretty intuitively.它使用 apache http 并非常直观地处理所有交互。

Use an existing library like Selenium or HttpClient to interact with a website.使用 Selenium 或 HttpClient 等现有库与网站交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM