Get Source Element from Mouse Trigger Event and Click Later in Sequence

Hi all,

I would like to store a specific element that is obtained from a mouse trigger event (ie, the element that the user clicks on). Then I would like the bot to click on that same element later in the workflow without having the user manually click on it. The initial element will be variable, so it needs to be set by the user’s initial click.

My current bot fails at the downstream click activity. Any suggestions?

1 Like

Hi, use ‘Find element’ activity and give the selector of the element which user is clicking
Now create a variable with uielement type and take that as output for above find element activity

Now in the code , you can use mouse trigger and input as above element variable

Kindly have a view on this thread

Cheers @EO_CPA

The issue I forsee with this solution is that it requires me as the developer to manually give the selector of the element that I think the user is going to click, rather than the users action of clicking being the defining moment of which element is to be used in the workflow.

Because I can’t foresee which element the user will click, how can I give the selector of that element to the Find Element activity before the user clicks themselves?

Hi, sorry for misunderstanding your question
Use monitor events activity first
Use click trigger as the trigger , you can use multiple click triggers with all the suspected elements on which the user may click
Now
Please use 'get source element" activity in the event handler sequence
And the output will be the element which user clicked

This makes sense to me, should work in other circumstances.

I think my problem is that the original element is alone in a list and has the selector below:
ctrl name=‘Client.Templates.TestOfDetails.ViewModels.TargetedTesti*’ role=‘list item’ />

Then a new element is created by the bot, and now the original element is NOT alone in the list and takes on an idx number in the selector:

Selector of original element after the new element is created, no longer alone in the list:
ctrl idx=‘2’ name=‘Client.Templates.TestOfDetails.ViewModels.TargetedTesti*’ role=‘list item’ />

The new element selector has idx=1. Looks like by creating a new element and adding it to the list, the original element is changed, and can no longer be found later on by the click function, which uses the stored original element as a variable.

1 Like

@EO_CPA

In this case, the way to solve it would be to slightly adapt the selector before the second click (based on the thing that changes).

You should still explore all the properties of the new selector, as the idx property is not the best one to rely on. My bet is that you can find the property that directly relates to something you know, i.e. the value robot knows because it added it to the list.

Then, as to updating the selector itself within the variable, there might be a method that can do it (using the Invoke Method activity).

However, a potentially easier way would be to use a simple .Replace method to replace the small bit of selector to make it work. Something like this:
image

I will give this a shot - thanks for the help.

Why is it that the Get Source Element activity can’t be performed as a result of a Mouse Trigger Event? Seems like there should be an easy way to store/track the element that the user clicks on at a particular junction in the workflow, regardless of the element that is selected and regardless of any dynamic selectors in those elements.

I can’t use vinay_reddy’s solution because the elements are going to be dynamic won’t be the same for different users, so there is no way to click “all possible elements the user could potentially click on”.

It can though. In my example, the clickSource variable is the output of the Mouse Trigger Event.
If I were to reuse that found element object, it simply clicks the same box again
(which paired with the True flag for RepeatForever of my Monitor Events window resulted in my robot having an infinite loop because each new click would generate a mouse event and click again :sweat_smile: whoops)

The only thing I had trouble doing is modifying the selector within the entire object. So instead, I’m passing just the selector string from that variable to the next Click activity, and as such I only have to do a simply text replace to change that selector to my linking (to click a different element).

3 Likes

The issue has been resolved. My problem was due to not using the latest package. Once I updated, I was able to use a mouse trigger and store the source element as a variable no problem. Thanks for all the help!

1 Like

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