My friend and I were discussing a script for automating a certain task and the solution involved using Selenium to automate the pressing of certain buttons.

However when we click the send button of a form, how do we know it always has the same function? Even if a script works the first 100 times, the page may totally change 101.

In our case, I would like to open my e-mail account and automatically respond to some messages. However it is possible the buttons can move around.

Therefore our automation task will break whenever the website changes and we can't do anything except build from scratch and identify the change however small it is.

Is there any way to build robust automation tasks?

Programmatically, it seems impossible to detect changes in JavaScript since these scripts can be thousands of lines long.

  • Are you trying to test web content built in your organization, or to drive web pages that are completely out of your control? – kevin cline Nov 6 '14 at 20:32
  • @kevincline for example. I want to check my Gmail and delete all messages matching a certain regex. – john mangual Nov 6 '14 at 21:53
  • In general, that's why for everything involving automation, you don't interact with a web application through web interface, but, in general, through an API.

    • If you try to access your own web application, create an API. Instead of Selenium, your automation task would be to simply make an API call with curl or similar tools.

    • If you try to access a third-party web application, there are chances you're not only doing it wrong, but also doing something which is prohibited by the owner of the concerned website. Unless you have a lawyer in your company, you consulted him, he explained you the risks of doing what you're doing and you understand and accept the risk, contact the owner asking for an API.

  • In your specific case, since your automated task involves accessing e-mails, you may want to search for those three keywords: POP3, IMAP and SMTP. Web interfaces should be irrelevant in your case.

  • Or maybe you don't even need to write a single line of code. Many e-mail clients contain filtering, as well as auto-response features; by combining both, you may find that the solution to your problem is just a clicks away (with a huge benefit of having exactly 0 LOC to maintain over the years).

Note: the fact that a button moves on a page shouldn't bother Selenium, since you're expected to access them through selectors, not by absolute position anyway.

  • I'm sure OP meant that the selectors for said buttons might change, not necessarily their physical positions on the page, but your point is well-received. – Neil Nov 6 '14 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.