Forum Discussion

Vallalarasu_P's avatar
Vallalarasu_P
Frequent Contributor
5 years ago

Xpath in Keyword Test, How to identify and perform operation on it ?

How to find the object using xpath expression and performing operation on the found object ?

  • I agree with cunderw .  Unless ABSOLUTELY necessary, you don't need to use XPath expressions to find objects in TestComplete tests.

     

    IF, however, you need to....

     

    1) Use "Call Object Method" operation in Keyword test to call the XPath method on your parent object

    2) USe "Set Variable Value" operation to set the "Last Operation Result" to the value of your variable

    3) Use that variable in code expressions and such within your keyword tests to identify your object

     

     

    It's point 3 which makes using XPath expressions in keyword tests VERY cumbersome because you can't just use "On screen action"... everything needs to be a code snippet or code expression from that point onwards.  You might as well write in code rather than a keyword test.

  • cunderw's avatar
    cunderw
    Community Hero

    I would highly advise against using Xpath in Test Complete and stick with the build object find methods and name mapping. What is the use case for wanting Xpath?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      I agree with cunderw .  Unless ABSOLUTELY necessary, you don't need to use XPath expressions to find objects in TestComplete tests.

       

      IF, however, you need to....

       

      1) Use "Call Object Method" operation in Keyword test to call the XPath method on your parent object

      2) USe "Set Variable Value" operation to set the "Last Operation Result" to the value of your variable

      3) Use that variable in code expressions and such within your keyword tests to identify your object

       

       

      It's point 3 which makes using XPath expressions in keyword tests VERY cumbersome because you can't just use "On screen action"... everything needs to be a code snippet or code expression from that point onwards.  You might as well write in code rather than a keyword test.

      • Vallalarasu_P's avatar
        Vallalarasu_P
        Frequent Contributor

        Is the below steps possible in Keyword test

         

        1) Maintaining Xpath in an external file (Excel or csv) / Project Variables for the list of object.

        2) Creating a keyword test (XPathObject- Based on below steps)  to parametrize the Xpath value 

        3) Calling the Keyword test (XpathObject) in each step of the test. 

         

        Another option is, How to use FindChildbyxpath  in Script test and parametrizing it throught out the keyword test .

         

        Regards

        Valla