Forum Discussion

vladd1's avatar
vladd1
New Contributor
13 days ago
Solved

Does TC have a .within() method similar to Cypress.io?

Hello, I am coming from working mostly with Cypress.io to developing in TestComplete. A feature we used often on my old team was the 'within' method. Basically you could grab a parent element of a website or dom, add the within method and then narrow down your search within that range. It helps to ensure the automation is looking at the right part of the page when testing, especially if testing a commonly used button, like submit. 

Ex:

<div class="main">
    <header class="login">
         <div class="loginBox">
               <h1 = "welcome to my app"\>
               <p = "please login with your email"\>
               <input\>
               <button class="submit"\>
        <\div>
   <\header>
   <p = "need help?"\>
   <input\>
   <button class ="submit"\>
<\div>

For this example to ensure the correct "submit" button is clicked I would, in Cypress:

cy.get(".login").within(() => {
         cy.get("button").should("have", "class", "submit").click();
}

The within method allowed the automation to find a parent element, and then search within those wrappers to find the child element. 

Does test complete have a way of doing this?