Forum Discussion

CMA_Senthil's avatar
CMA_Senthil
Occasional Contributor
9 years ago
Solved

What is an appropriate method to perform a native click in Chrome and Opera?

 Hi,

 

I have an issue with native click in Chrome and Opera. I have the below line of code in my script which retuens an anchor link

 

entityObj.childNodes[0].childNodes[0] - This returns an object with below properties

 

outerHTML - <a href="javascript&colon;void(0)" class="eqjs-ep-entity-node-button" savedtabindex="[object Object]" tabindex="-1"></a>

 

tagName - A

 

href - javascript&colon;void(0)

 

When I try to execute the code "entityObj.childNodes[0].childNodes[0].Click()"

 

In IE and Firefox

entityObj.childNodes[0].childNodes[0].Click() = Trigger the click event properly

 

In Chrome and Opera

entityObj.childNodes[0].childNodes[0].Click() = Object doesn't support this property or method

 

Any one suggest a right Click() method which will work in Chrome and Opera? 

 

See the attached object browser screenshot.

 

  • Hi Senthil,

     

    I would suggest that you use TestComplete's special methods, EvaluteXPath of FindChildByXPath, to get an object based on it's HTML information. Here is an example:

    // Call the function
    var obj = page.FindChildByXPath("//A[@class='eqjs-ep-entity-node-button')]", true);
    
    // 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.");
    }

     

    Your code may not work because of the different object trees that browsers can create in a different way.

5 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Senthil,

     

    I would suggest that you use TestComplete's special methods, EvaluteXPath of FindChildByXPath, to get an object based on it's HTML information. Here is an example:

    // Call the function
    var obj = page.FindChildByXPath("//A[@class='eqjs-ep-entity-node-button')]", true);
    
    // 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.");
    }

     

    Your code may not work because of the different object trees that browsers can create in a different way.

    • CMA_Senthil's avatar
      CMA_Senthil
      Occasional Contributor

      Hi TanyaGorbunova,

       

      Thank you for the reply. I managed to solve the issue by using FindChild method but it takes little more time (approximately 6 to 7 seconds) to identify the object if the object does not have idStr property even if you set proper level to search.

       

      If an object has an idStr then FindChild returns object pretty fast. 

       

      Is there any way to use wildcard on the methods EvaluteXPath / FindChildByXPath

       

      // Call the function

      var obj = page.FindChildByXPath("//A[@class='eqjs-ep-entity-node*')]", true);

       

       

       

      • TanyaYatskovska's avatar
        TanyaYatskovska
        SmartBear Alumni (Retired)

        Hi Senthil,

         

        You can use the contains function:

        var obj = page.FindChildByXPath("//A[contains(@class,'eqjs-ep-entity-node')]", true);