TestProject Forum
Powered by leading experts in the test automation community

How to handle dynamic XPATH

Good day.

I’m just wondering on how can I create an element action using a dynamic XPATH and point that element every test run?

Mailinator’s individual inbox email for example.

Thanks!

Hi @gerard.benavides,

How to create a dynamic element in TestProject

Click on the “+” icon to create a new step and then, click on “Select element”:

Click again on the “+” icon to create a new parameter:

To create a new element, fill the below details:

  • Name
  • Description (optional)
  • Select the element’s type (input, div, span, etc.)
  • Locator strategy (ID, Name, XPath, etc.)
  • Provide the locator’s value

Between the single quotes in the below screenshot, we are going to add a parameter instead of a static text. To do so, we need to click on the “+” icon in the below screenshot:

To add a parameter to the locator value, we have to create one. Click on the “+” icon to create a new parameter:

To create a new parameter, fill out the below details:

  • Name
  • Description (optional)
  • Value

Then, click on the “Create” button to complete the element creation:

You can see now that the newly created parameter is used in the XPath value. This will make our element a dynamic one!
Click on the “Save” button to save the element’s value:

That’s it! To complete the element creation, simply click on the “Add element” button.

Let me know if you’ll need help with that :slight_smile:

Amit

1 Like

Hello @amit.yahav,

Really appreciated your detailed instructions! Just want to verify, does TestProject disable creating steps inside of an email content?

Thanks!

You’re welcome @gerard.benavides!

Regarding the email content, can you please elaborate? What exactly are you trying to do and how it’s failing?
Also, a screenshot or a short video would really help :slight_smile:

Hi @amit.yahav,

It’s not actually failing, I just can’t create steps inside a content of an email. Refer the the attached below, marked in red.

This is a sample of the same email content opened when not using TestProject:

Thanks!

Hi @gerard.benavides,

It looks like that element is an iframe. Can you please check? Just to make sure.
If it is an iframe, you have two options:

  1. Create a coded test that handles this iframe using our Java/C# SDKs. You can upload this coded test back to TestProject and combine it in your recorded test.

  2. In the recorder, use the element action called “Switch to iFrame”. Since it’s an element action, you will have to create a new element for this iFrame. Once you would do that and switch to this iFrame, you would be able to perform actions on the elements that are inside this iFrame. The recorder will still gray out this element, but the actions should work fine.

We are currently working on a new recorder layout that will allow you to handle iFrame elements. It’s scheduled to be released by the end of March 2020.

Let me know if you’ll need my help with that :slight_smile:
Amit

1 Like

Hi @amit.yahav,
I’ve tried this method and discovered that the graye out part is not an iframe. [quote=“amit.yahav, post:6, topic:911”]

  1. In the recorder, use the element action called “Switch to iFrame”. Since it’s an element action, you will have to create a new element for this iFrame. Once you would do that and switch to this iFrame, you would be able to perform actions on the elements that are inside this iFrame. The recorder will still gray out this element, but the actions should work fine.
    [/quote]

I’ve coordinated with the back-end guys for a workaround regarding with this scenario and they’re already working on it.

Thanks for your help as always!

Hi @gerard.benavides,

The gray part can either be iFrame or that your website is responsible for graying it out.
Are you sure that it’s not iFrame? Is there a chance I get access to this website to check it myself?

Yes, when running the ‘Switch to iFrame’ addon, it says that container is not an iFrame.

You can replicate this by going to mailinator.com and entering ‘zoffmncexspgnfp@mailinator.com’ on the text box and opening the email ‘Recover your password’. Refer to the attached


Hi @gerard.benavides,

I’ve looked into this website and it is an iframe element. You can see it in the screenshot below:

Try this solution:

  1. Create a new element manually and set these values to it:

  2. Use the element action “Switch to iFrame” on this element

  3. Try to perform actions on the elements inside this iframe.

Let me know if it helped you :slight_smile:
Amit

1 Like

Wow that’s great!

I was able to perform clicking on the grayed out field using the NLP addon, though it takes at average of 15 seconds to perform, but that solves my problem!

Really appreciated your assistance towards my concerns everytime. Thanks @amit.yahav !

You’re welcome @gerard.benavides!
We are always here to help :wink: