1

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?

Community
  • 1
  • 1
david blaine
  • 5,683
  • 12
  • 46
  • 55
  • The reason for doing this little project is in this question - http://stackoverflow.com/questions/17329996/want-to-create-a-form-filler-is-java-jsp-html-enough – david blaine Jun 28 '13 at 06:05
  • You can certainly do this in native Java along with the Selenium library, but it isn't possible (or at least, *shouldn't be done*) using the IDE. – Arran Jun 28 '13 at 08:58

1 Answers1

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.

Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • Is it possible to make "some software" run selenium scripts according to a schedule ? That could free me of the need to make java code for my purpose. I don't even know how much time it will take to learn basic selenium java api and then make java code. Is it something that can be done in 2-3 hours ? The form is very simple. 6-7 simple fields only. All HTML, no JS and such. – david blaine Jun 28 '13 at 16:43
  • I would use python to run the tests. Then call the python script from windows task manager or linux cron job. You can also call your java code from a task. If you can run it in command line then you can schedule it. – PHPGuru Feb 12 '14 at 06:10