How to get text from a web element in Cypress? How to use text() method in Cypress?

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

ความคิดเห็น • 32

  • @CodenboxAutomationLab
    @CodenboxAutomationLab  5 วันที่ผ่านมา

    📌 Need any Help? Book an Appointment with me for Resume Building/Mock Interview/1:1 Mentorship: 👉topmate.io/sariful
    ✅ Looking forward to connecting with you all and making a difference together!🙏🚀

  • @Pingsmingu
    @Pingsmingu 8 หลายเดือนก่อน

    Very nicely explained , please do more videos like this

  • @ratven_alexander
    @ratven_alexander ปีที่แล้ว

    So easy and so useful!
    Thank you Sariful!

  • @parveentaher1192
    @parveentaher1192 2 ปีที่แล้ว +1

    Thanks a lot. Your lecture is details and very easy to understand specially for non IT individual.

  • @feeding.animals9710
    @feeding.animals9710 3 ปีที่แล้ว +4

    Could you please make a video on how to implement page object model completely(Indetail) in cypress

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  3 ปีที่แล้ว +1

      Stay tuned. Soon we will publish tutorials about page object model in Cypress

    • @feeding.animals9710
      @feeding.animals9710 3 ปีที่แล้ว +3

      @@CodenboxAutomationLab thanks a lot please make complete series on it in generic way

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  3 ปีที่แล้ว +2

      Here is the tutorial for page object model: th-cam.com/video/j2t50-z3rYo/w-d-xo.html

    • @feeding.animals9710
      @feeding.animals9710 3 ปีที่แล้ว +1

      @@CodenboxAutomationLab thanks alot 🙂🙂

  • @ajeetpatel3533
    @ajeetpatel3533 ปีที่แล้ว

    And when text get changed every cypress automation run then how to get text from element and store variables

  • @VinodPatelC
    @VinodPatelC ปีที่แล้ว +1

    Thank you. I am referring your videos and it is very useful. I tried the same code and it is worked for me in finding the text of label and button using .invoke('val') function. But what can do for drop down value , [select tag]. i want to get the text of first element of drop down. thank you

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  ปีที่แล้ว +1

      Try this:
      cy.get('selector-for-dropdown').invoke('val')
      .then((value) => {
      cy.get(`selector-for-dropdown option[value="${value}"]`).then((option) => {
      const text = option.text()
      // Use the text value as needed in your test
      })
      })
      Note: Here, selector-for-dropdown is the CSS selector for your drop-down element.

    • @VinodPatelC
      @VinodPatelC ปีที่แล้ว +1

      @@CodenboxAutomationLab Ok. Thank you. I will try this today.

  • @Lakshmi_Panchagavya
    @Lakshmi_Panchagavya 2 ปีที่แล้ว

    Thanks alot

  • @rajahassan8522
    @rajahassan8522 3 ปีที่แล้ว

    How to interact with extension using cypress ? is it possible? For example interaction with metamask extension using cypress

  • @elmariscal5394
    @elmariscal5394 3 ปีที่แล้ว +1

    Hi , what about if you want to create a method to return the text of an element. Is that posible ?

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  3 ปีที่แล้ว

      Yes, it's possible. You can create a separate method and follow the same code as per our tutorial and just put the actual text on a variable using the text() method , then return that variable at the end. That's all.

    • @sunilkumar-gx4wt
      @sunilkumar-gx4wt 3 ปีที่แล้ว

      @@CodenboxAutomationLab Can you please make a video on this

  • @rudeshhatkar4131
    @rudeshhatkar4131 2 ปีที่แล้ว +1

    How to read the innertext of an element if it is a number format?

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  ปีที่แล้ว

      You can use the .text() method to get the inner text of an element, and then parse it as a number using JavaScript's parseInt or parseFloat function.
      Example: cy.get('selector-for-element').then(($el) => {
      const text = $el.text()
      const number = parseFloat(text)
      // Use the number value as needed in your test
      })
      Here, selector-for-element is the CSS selector for the element whose inner text you want to retrieve. The code retrieves the inner text using the .text() method, and then converts it to a number using the parseFloat function.

  • @CodenboxAutomationLab
    @CodenboxAutomationLab  ปีที่แล้ว +1

    Thanks for watching. 🌟 Please hit on LIKE ❤ Share 🔥 SUBSCRIBE for more AMAZING content on every week! 🌟

  • @rudeshhatkar4131
    @rudeshhatkar4131 2 ปีที่แล้ว +1

    How to invoke numbers as innertext in cypress?

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  ปีที่แล้ว

      You can use the .text() method to get the inner text of an element, and then parse it as a number using JavaScript's parseInt or parseFloat function.
      Example: cy.get('selector-for-element').then(($el) => {
      const text = $el.text()
      const number = parseFloat(text)
      // Use the number value as needed in your test
      })
      Here, selector-for-element is the CSS selector for the element whose inner text you want to retrieve. The code retrieves the inner text using the .text() method, and then converts it to a number using the parseFloat function.

  • @tigran7777777777
    @tigran7777777777 3 ปีที่แล้ว

    How to get the text from the web element after updating the text on this element?
    Please help!

  • @blablagswjsvsns134
    @blablagswjsvsns134 3 ปีที่แล้ว

    Second test does not make any sense. How it get to know about that it have to hold the text or another property ?

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  3 ปีที่แล้ว

      .then(function(text2)) has the knowledge about all the properties of get(' ') element. It's up to you what property you want to get. That's why we applied text() method to get the text from that element. Hope that make sense.

  • @genismestres3606
    @genismestres3606 2 ปีที่แล้ว +1

    Do you know how to obtain text from input method? .text() wouldn't work.

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  ปีที่แล้ว

      you can use the .invoke() method to call the .val() function on the input element. Here is an example of how you can do this: cy.get('input[name="your-input-field-name"]')
      .invoke('val')
      .then((value) => {
      // value will contain the text entered in the input field
      });
      You can also use the .should() method to make assertions as:
      cy.get('input[name="your-input-field-name"]')
      .should('have.value', 'expected value');

  • @shirishcin
    @shirishcin 3 ปีที่แล้ว

    just read the text and capture to a variable. too many unnecessary information was not needed.

    • @CodenboxAutomationLab
      @CodenboxAutomationLab  3 ปีที่แล้ว

      Well, we have to consider all different types of viewer. Every one is not your level. Hope you understood that. Thanks!