My friend and I were discussing a script for automating a certain task and the s
ID: 647881 • Letter: M
Question
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.
Explanation / Answer
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.