Java和Selenium用于填写Web表单? [英] Java and Selenium for web form filling?

查看:364
本文介绍了Java和Selenium用于填写Web表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动填写网络表单。我使用Selenium IDE创建一个脚本,该脚本使用一个命令来搜索网页中的指定文本。

I wanted to fill a web form automatically. I used Selenium IDE to create a script which ENDS with a command that searches for the specified text in the webpage.

我想根据这篇文章采取行动。如果text = congratulations,则发送电子邮件到某个地址。如果没有,则单击确定按钮。我不认为Selenium IDE可以做这个If-else逻辑并自己发送邮件(在selenium ide中使用if / else

I wanted to take action based on this TEXT. If text = congratulations, then send an e-mail to some address. If not, then click ok button. I don't think the Selenium IDE can do this If-else logic and send mail on its own (Using if / else in selenium ide).

所以,我想用Java代码运行这个Selenium HTML脚本,找出是否找到或不找到所需的文本 - 如果是,则发送邮件;否则Java代码将点击确定按钮。

So, I thought of using Java code to "run" this Selenium HTML script, find out if the desired text was found or not - if yes then send mail; otherwise the Java code will "click" the ok button.

这种方法有意义吗?是否可以使用Java和某种Selenium Java API来实现这一点?

Does this approach make sense? Is it possible to do this using Java and some kind of Selenium Java API?

推荐答案

你不能在Selenium中可靠地做到这一点IDE。真正的方法是使用Java + Selenium WebDriver,事情变得非常简单:

You can't do this reliably in Selenium IDE. The real way to do this is to use Java + Selenium WebDriver, where things get pretty easy:

// acquire text
if (acquire.equals("congratulations")) {
    sendMail("Something, tada badum tss!");
} else {
    driver.findElement(By.id("myButton")).click();
}

邮件发送部分可以通过数千种方式完成,取决于你的方式想要做到这一点。从哪里开始的是 JavaMail网页。如果您对此感到不舒服,您还可以查看最常见的包装: Apache Commons电子邮件 Jodd

The mail sending part can be done in thousands of ways and depends on how you want to do it. The basic point where to start is the JavaMail Webpage. If you're uncomfortable with it, you may also look at the most common wrappers for it: Apache Commons Email and Jodd.

这篇关于Java和Selenium用于填写Web表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆