Java and Selenium for web form filling?

偶尔善良 提交于 2019-11-28 11:41:57

问题


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.

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).

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.

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


回答1:


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();
}

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.



来源:https://stackoverflow.com/questions/17358228/java-and-selenium-for-web-form-filling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!