Results 1 to 6 of 6

Thread: Handling nth element

  1. #1
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    18

    Default Answered: Handling nth element

    I'm wondering how can one locate nth element if there is no unique element in ExtJS application.
    For an instance i need to pick element from first pickerfield on following screen:

    snibedisnib.png

    but niether one has unique element (apart from autogenerated Id and name which I'm avoiding to use as locator) so I can locate only atleast two.
    My question is how can one locate nth element (pickerfield let's say) in sencha test for an instance if I saved element in Page object as "pickerName"

    can I do something like: stpo.pickerName()[0].expand.selectbyText("something")

  2. "nth-child" in a Component Query allows you to distinguish between the multiple component matches. From the documentation:

    nth-child Filters Components by ordinal position in the selection.

    So if you have 7 matching buttons on a page when using this locator:

    Code:
    button[text="Hello"]
    And you want to reference the second matching button, you can use nth-child to select that single button like this:

    Code:
    button[text="Hello"]:nth-child(2)
    In the context of Sencha Test, this would look like this, and would allow you to avoid matching multiple components:

    Code:
    ST.button('button[text="Hello"]:nth-child(2)')

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    394
    Answers
    74

    Default

    You can use "nth-child" in the locator to reference a specific instance of a component when there are multiple matches:

    Code:
    ST.button('button[text="Small"]:nth-child(2)')
        .click();
    Daniel Gallo
    Sales Engineer
    Sencha

  4. #3
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    18

    Default

    which means that it only browse through child elements. and it still matches more than one element.
    Still getting:
    Failed with error "Component Query locator matches multiple items...

    I was hoping to execute somthing like i manage to do in console, for instance:

    Code:
    Ext.ComponentQuery.query("pickerfield[emptyText='SOME_TEXT']")
    which finds 10 elements and I just reffer to the specific one with

    Code:
    Ext.ComponentQuery.query("pickerfield[emptyText='SOME_TEXT']")[0]

    I even tried with just :nth(n) like it's in documentation

    E:nth(n) the nth E in the resultset (1 based)
    Code:
    ST.element("pickerfield[emptyText='epmty_text']:nth(0)").focus();
    but I'm getting error:

    Failed with error "g.pseudos[u] is not a function". Fix the error and try recording again


    Code:
    Even ST.element("pickerfield[emptyText='SOME_TEXT']"[0])
    inerprets it like it takes letter as param in square brackets

    Timeout waiting for target (i) to be available for ST.future.Element. Fix the error and try recording again.

    I'm not sure if you're understand my issue. but essentially i want to manipulate with specific element when multiple are found.

  5. #4
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    18

    Default

    anyone tho?

  6. #5
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    394
    Answers
    74

    Default

    "nth-child" in a Component Query allows you to distinguish between the multiple component matches. From the documentation:

    nth-child Filters Components by ordinal position in the selection.

    So if you have 7 matching buttons on a page when using this locator:

    Code:
    button[text="Hello"]
    And you want to reference the second matching button, you can use nth-child to select that single button like this:

    Code:
    button[text="Hello"]:nth-child(2)
    In the context of Sencha Test, this would look like this, and would allow you to avoid matching multiple components:

    Code:
    ST.button('button[text="Hello"]:nth-child(2)')
    Daniel Gallo
    Sales Engineer
    Sencha

  7. #6
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    18

    Default

    Quote Originally Posted by daniel.gallo View Post
    "nth-child" in a Component Query allows you to distinguish between the multiple component matches. From the documentation:

    nth-child Filters Components by ordinal position in the selection.

    So if you have 7 matching buttons on a page when using this locator:

    Code:
    button[text="Hello"]
    And you want to reference the second matching button, you can use nth-child to select that single button like this:

    Code:
    button[text="Hello"]:nth-child(2)
    In the context of Sencha Test, this would look like this, and would allow you to avoid matching multiple components:

    Code:
    ST.button('button[text="Hello"]:nth-child(2)')
    Works well!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •