Skip to main content
Home
  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact
programsbuzz facebook programsbuzz twitter programsbuzz linkedin
  • Log in

Main navigation

  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact

Cypress siblings command

Profile picture for user devraj
Written by devraj on 12/01/2021 - 09:44

Earlier we have discussed parent, parents, and children command now it's time to discuss another related command which is a sibling.

Sibling means two or more children or offspring or elements in HTML terms, having parent elements in common. With siblings command, you will get Get siblings DOM elements that share the same parent. .sibling() command will yield new elements or elements if found.

Syntax

.siblings()
.siblings(selector)
.siblings(options)
.siblings(selector, options)

Here, a selector to identify matching DOM elements and for options, we can have 2 values log and timeout.

Example

Again, this command can not be chained directly with cy. For demo, we will be working on the top menu of ProgramsBuzz

cypress sibling demo

 it.only('sibling demo', () => {
        cy.visit('/')

        // Yield all li's siblings for top navigation - 6 elements
        cy.get('div.gva-navigation > ul > li').siblings()

        // Click on Ask doubt link
        cy.contains('Ask Doubt').click()
        
        // Yield all li's siblings with class '.menu-item--active-trail' i.e. ask doubt (1 element)
        cy.get('div.gva-navigation > ul > li').siblings('.menu-item--active-trail')

        // output 5 elements
        cy.get('div.gva-navigation > ul > li.menu-item--active-trail').siblings()
    })

In the above code first, we counted a number of menu items using sibling, which will return 6 items, then after clicking on the ask doubt link, we are checking how many items are active. Obviously, that is the one which we clicked with the link title Ask Doubt.

In the 4th command, after finding the active element (Ask Doubt) using the selector. We are finding siblings of Ask Doubt, which are the remaining element except for the ask doubt, and hence count will be 5.

Related Content
Cypress Tutorial
Cypress parent command
Cypress children command
Tags
Cypress
  • Log in or register to post comments

Choose Your Technology

  1. Agile
  2. Apache Groovy
  3. Apache Hadoop
  4. Apache HBase
  5. Apache Spark
  6. Appium
  7. AutoIt
  8. AWS
  9. Behat
  10. Cucumber Java
  11. Cypress
  12. DBMS
  13. Drupal
  14. GitHub
  15. GitLab
  16. GoLang
  17. Gradle
  18. HTML
  19. ISTQB Foundation
  20. Java
  21. JavaScript
  22. JMeter
  23. JUnit
  24. Karate
  25. Kotlin
  26. LoadRunner
  27. matplotlib
  28. MongoDB
  29. MS SQL Server
  30. MySQL
  31. Nightwatch JS
  32. PactumJS
  33. PHP
  34. Playwright
  35. Playwright Java
  36. Playwright Python
  37. Postman
  38. Project Management
  39. Protractor
  40. PyDev
  41. Python
  42. Python NumPy
  43. Python Pandas
  44. Python Seaborn
  45. R Language
  46. REST Assured
  47. Ruby
  48. Selenide
© Copyright By iVagus Services Pvt. Ltd. 2023. All Rights Reserved.

Footer

  • Cookie Policy
  • Privacy Policy
  • Terms of Use