Forum Discussion

josette_merhy12's avatar
josette_merhy12
Occasional Contributor
12 years ago

Find element and find object

hello, i m trying to find an object using the Find method. this method returns an object, i can click on it even if it s not a button. But when i use FindChildByXPath method, an element is returned. if the element was a span, i cant use the action click like i do with an object.



how can i solve this issue if i have an element i want to click?

is there any function to convert the element to object?



i am using Jscript language and jquery.



thanks...

1 Reply


  • Hi Josette,


     


    The Click method is some kind of a universal method. So, it should work for SPAN. It worked for my case:


     


    HTML:


    <script>


    function myFunction()


    {alert ("Some Text");}


    </script>


    <html>


    ...


    <div>We are executing the <span id="textSpan" style="color:blue;font-weight:bold" onclick="myFunction()">Test</span>.</div>


    </html>


     


    This is the JScript code run from TestComplete:




    function main()


    {


        var page = Sys.Browser("iexplore").Page(*);


     


        var obj = page.FindChildByXPath("//span[@id='textSpan']", false);


        if (obj != null)


        {


          obj.Click(); 


       }


        else


        { 


          Log.Error("The element was not found.");


        }


    }