Question regarding injecting javascript and selector

Hello guys

I am trying to automate some web activities basically for things like clicking, inputting credentials, downloading documents. I am trying to avoid using selectors as it is a bit unstable. I already know there is no open API for this website. I am looking at the injecting javascript activity. It seems like injecting javascript works on the HTML doc, which is just like how selectors work. Is there any difference between using selectors and injecting javascript? is the latter one better in any way? is the latter dangerous in any way?

Thank you guys for the help!

HI @R_R

Interesting… are you thinking of using a different technology that does not rely on underlying application selectors to identify web automation … an inter-dependent technology that does not relying on application/OS.

Could you give an example or explain a bit more to help me understand better ?

Hi @R_R ,

I doubt InjectSelector is a viable alternative for Selectors. For basic stuff, it might be ok, but it could get complicated for activities like Extract Data. Why do you mean by unreliable selectors? Can you provide some examples and how they change from a run to another?

Hello! The reason I am thinking of using injecting javascript activity is because: Websites regularly make updates on their HTML layout, which will break the bot if the bot relies on selectors to work. Injecting javascript activity seems to avoid manual clicking on website UI, however, it still works on the HTML doc. I am afraid that changing the website layout will also break the injecting javascript activity. Therefore I am curious to know if that is the case and if this activity has any advantages over using selectors to interact with websites.
An example of a better tool to interact with a website than selectors is through web API. It bypasses the changing HTML layout and directly gets the data from the web server, however, The website I am talking about does not have an open API

Thank you for your reply.

I am not trying to replace selectors, I am trying t use the inject javascript activity just for clicking on a certain UI element within a website such as: an input field so we can input user credentials, clicking download button to download some files. I am not using it to extract datatable.

By unreliable selectors, I mean, websites always update its webpage layout, which changes its html tags, or class, etc. if the bot relies on selectors, this will break the bot. What I am asking is Can injecting javascript activity avoid this? does this post any risks if it does?

@R_R , I understand now, controls generally respond to events and they have a flag called “isTrusted”. There are cases of event handlers added on controls that may not handle not trustable events. Triggering events programmatically (elem.click or RaiseEvent or any other method) is generating events that have that flag set to false, so this is one issue you may encounter during the process. When using the activities, you can execute a click with hardware events which sends the events to your OS event handler, and in the end, trusted events will be raised.

Also, a similarity between the two methods is that, in either of the cases, you need to find the target element by something, tag, id, css-selector, so an unreliable UI can also affect the InjectJS activity.

1 Like

Thank you so much man, really appreciate it!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.