Forum Discussion

chandreshp's avatar
chandreshp
Occasional Contributor
10 years ago

Clicking on li html tag does not fire its click event.

Hi,



I have a li html element which has click event set for it.



<ul class="button">

   <li class="save-class" id="SaveChanges" style="' onClick="myJS.SaveChanges();">

     <img src="C:\correct.png">

      <span>save</span>

   </li>

</ul>



I grab the li object using getElementsByTagName("li").namedItem("SaveChanges") but when I perform click action for this by getElementsByTagName("li").namedItem("SaveChanges").click() it does nothing.



Any help on how to fire click event for this element?

7 Replies

  • chandreshp's avatar
    chandreshp
    Occasional Contributor

    Hi Tanya,


     


    Thanks for your help.


     


    Here the issue is not with the finding object, I am able to grab the object successfully but the onClick event is not getting executed correctly.


     


    However I found root of this. The issue is that onClick method "myJS.SaveChanges();" is not returning any value. So TestComplete was not able to identify that respective method got executed or not. When I manually put "return true;" at the end of myJS.SaveChanges() method and ran the script it worked!



    So I am gonna have to contact Dev team regarding this and see what we can do.



    Thanks everyone!


     



    • Vivek72's avatar
      Vivek72
      Contributor

      Hi Chandresh

       

      I came across the same problem and need to find f the solution you applied can help me too.

      Could you please give me an example how you did this:

      "When I manually put "return true;" at the end of myJS.SaveChanges() method and ran the script it worked!"

      And could you also give me sample script that makes it work? I use vbscript and my script goes as follows:

      Set acceptbtn = cell.FindChildByXPath("//*[@onclick='inlineGridEditor.saveItem(0)']",False)

      Call acceptbtn.Click

       When I run the above code it identifies the object but throws 'click method doesn't work for the object' error. The cell object mentioned doesn't have any child objects in my TC object browser. So I had to use findchildbyXpath method to find the element.

       

      It would be of great help to me if anyone can help me out on this.

       

      Thanks & Regards

      Prashanth


  • Hi,



    Sys.Browser("firefox").Page("*").Find("Name","SaveChanges",1000,True).Click


  • chandreshp's avatar
    chandreshp
    Occasional Contributor
    Hi,



    Thanks for your help.



    I have tried that but it did not work. Find method did not return any objects. I also tried by searching through its "id" property but that also did not work.



    I tried below and observed that it does click on button but somehow doesn't fire the click event which is specified for onClick.



    Sys.Browser("iexplore").Page("*").Panel("my_panel").getElementsByTagName("li").namedItem("SaveChanges").click();

  • Hi,



    Maybe namedItem("SaveChanges") is parent of Link(0) or somethink?



    The easiest way to check it: try to use "Object Spy" on your link, then copy "FullName" and use .Click



    Regards,


  • chandreshp's avatar
    chandreshp
    Occasional Contributor
    Hi,



    I looked into it and saw that namedItem("SaveChanges") is not parent of anything. There is no child element like link or anything, it shows only basic control properties.



    TestComplete identifies that control as

    Sys.Browser("iexplorer").Page("*").Panel("Placeholder").TextNode("SaveChanges").Image("correct_png") and I tried .Click() after that but it did not work.



  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Chandresh,

     


    It's better to use the FindChildByXPath method to find the object based on its HTML parameters. Here is an example:


     




      //JScript 


      // ...


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


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


        // Check the result 


      if (obj != null)


        {


          // If the element was found, click it


          obj.Click(); 


       }


      else


        { 


        // If the element was not found, post a message to the log


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


        }