Forum Discussion

DSmachineWorld's avatar
DSmachineWorld
Contributor
7 days ago
Solved

Way to map dynamic button (Web)

I have a button which is identified in the web application by taking the first letter of the first name and the first letter of the second name.

I don't think xPath will work to try and do a regex. Can I script a test in Python?

  • Python and regex should work as well.  It will likely require a

    buttons = page.FindAllChildren("ObjectType", "Button", 10)

    and then a loop through the found buttons against a regex pattern to retrieve the target button. 

    P.S.  (This could be slow and brittle depending on search depth and page structure / naming)

5 Replies

  • scot1967's avatar
    scot1967
    Icon for Champion Level 2 rankChampion Level 2

    Python and regex should work as well.  It will likely require a

    buttons = page.FindAllChildren("ObjectType", "Button", 10)

    and then a loop through the found buttons against a regex pattern to retrieve the target button. 

    P.S.  (This could be slow and brittle depending on search depth and page structure / naming)

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Icon for Champion Level 3 rankChampion Level 3

    Perhaps you can provide a detailed example including identified XPath to consider, but I am sure you can do it using XPath. 

    Using Python you can do a lot, and again details of what you are trying to accomplish and how to do it.

  • The Name Mapping has the Name mapped to:

    FindElement("//button[contains(., 'AA')]")

    where the test client has a first name beginning with "A" and last name beginning with "A". So the dynamic part is here.