Forum Discussion

vladd1's avatar
New Contributor
2 months ago

Does TC have a .within() method similar to

Hello, I am coming from working mostly with 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. 


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

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?