Forum Discussion

pbaus's avatar
pbaus
Occasional Visitor
3 months ago

Dynamic Values in XPATH

Hi,

I am getting dynamic values in my XPATH (every time when I execute the highlighted number changes). 

 //div[@role='main']/form[@id='form_47_0']/div/div/div/button[@name='SystemDefinedSaveButton'

If anybody know how to make these numbers as generic at the name mapping level.

Thanks

 

2 Replies

  • eykxas's avatar
    eykxas
    Regular Contributor

    Hi ! Usually, these id are generated by the web browser at the loading of the webpage. You can't make these id generic without modifying the app/website itself.

    Instead, you could use the contains method of xpath. > //div[@role='main']/form[contains(@id, 'form_')]/div/div/div/div/button[@name='SystemDefinedSaveButton']

    If you have multiple forms in your webpage, try to find a unique value inside the form you are looking then build your xpath from this point.

    Example : //div[contains(@title, 'My Form Title')]//ancestor::form/div/div/div/div/button[@name='SystemDefinedSaveButton']

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Also see,

    https://community.smartbear.com/discussions/testcomplete-questions/object-not-found-when-using-a-variable-in-keyword-test-on-screen-action/255816

    https://community.smartbear.com/discussions/testcomplete-questions/web-testing---switch-between-using-findelement--xpath-to-grab-objects-and-using-/252299