Clicking using JavaScript

I am creating an element using execute JavaScript action but I am getting this error upon running it:

Action failed using following locators:

  1. XPATH=//div[4]
    TimeoutException: Timeout occurred while trying to perform the action. Element was not found

  2. XPATH=/html/body/div[4]
    TimeoutException: Timeout occurred while trying to perform the action. Element was not found

How can I fix this?

Hi @mgg7934,
Did you use the recorder to record an action on the element after you created it?
Can you please make sure the following:

  • Your element is created before the test tries to locate it.
  • Your locators are valid when the element is present.
  • Your javascript execution doesn’t fail for some reason.

Let me know if you managed.

Hi @Amit.Lacher

My website is all shadow dom (just shows generic web element), so I made an element for the textbox which will show in developer tools that I can use. After that I copied the JS path of the element on and pasted into the execute JavaScript action with .value=“text” at the end.

Using this::

This is the error (picture below) I am getting now after the above problem has been resolved. This is when I’m trying to input the text into the textbox. If I run the text input step individually, it runs without any error but it shows error if I run it with other steps or the whole test script.

the test error while running the test step with other steps:

the test step running individually:

These are the steps I used to create an element:

  1. locates the mouse location of the element on the website:
    image
    image

  2. creates a new element (purple square) on the current element with the coordinates of where the new element to be created in args:
    image

3.click on the new element
image

  1. after this code, I run the click action and the new element will be shown in the Dom
    image

  2. I’m trying to input the text into the textbox using JS path of the new element obtained from the developers tool
    image

I did everything as the steps but where did I make a mistake? :thinking:

Hi @mgg7934,
The error you see is happening because you cannot send keys to an element that has no events or no value.
From the next agent version 3.4.2 you will be able to perform sendkeys action with Robot.
Which should allow you to automate any basic scenario such as sendkeys and click actions.
I will be sure to update you here when it’s out.

Hi @Amit.Larcher

I’ll wait for 3.4.2 agent version but isn’t there anything else I can do to make the test step work or to send keys using javascript code?

You can click on the element,
And then when it’s available under the shadow dom element in the dev tools.
Create a javascript locator for the text field and then use .value="your text"

Hi @Amit.Lacher

I already tried that

@mgg7934
Did you try to change the value of the shadow-dom element or the value of the element you have created?

@Amit.Lacher

The value of the element

The element you have created is either not an input element, or setting it’s events to none disables the option to send keys to that element.
Please try to use the first method and create a javascript selector for the actual input field in your application.

Hi @mgg7934,
This has been resolved by changing the steps order in your test. :smiley:
Feel free to reach out if you face any issue.

Kind regards
Tal

Hi @mgg7934,

The addon Robot Operations is out and it should help you perform the actions you were looking for.

You can download the addon here:

https://app.testproject.io/#/addons/community

And read the documentation here:

This topic was automatically closed after 180 days. New replies are no longer allowed.