Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfBounds if CollectionElement used as context does not exist #747

Closed
CaBocuk opened this issue May 27, 2018 · 5 comments · Fixed by #837
Closed

IndexOutOfBounds if CollectionElement used as context does not exist #747

CaBocuk opened this issue May 27, 2018 · 5 comments · Fixed by #837
Assignees
Labels
Milestone

Comments

@CaBocuk
Copy link

CaBocuk commented May 27, 2018

The problem

If you use not existing CollectionElement as search context for a collection -> IndexOutOfBounds is thrown

Details

Such code for looking for Collections

    @Test
    public void test () {
        open("https://yandex.ru");
        $$("not-existing-locator").first().$$("locator").isEmpty();
    }

Produces java.lang.IndexOutOfBoundsException: Index 0 out-of-bounds for length 0

But same logic for looking for Elements

    @Test
    public void test () {
        open("https://yandex.ru");
        $$("not-existing-locator").first().$("locator").exists();
    }

Works fine. And $$("not-existing-locator").first().$("locator").exists(); has false value.

Seems to have some kind of inconsistency. Does it work as designed?

Tell us about your environment

Selenide Version: 4.11.4

@sidelnikovmike
Copy link
Contributor

hm. Code fails on first() I think. You are trying to get first element of list with size = 0. It is java common behaviour.

@CaBocuk
Copy link
Author

CaBocuk commented Jun 29, 2018

@sidelnikovmike sure it is, but it works fine for
$$("not-existing-locator").first().$("locator").exists();
and this different behavior is a bit confusing imo

@asolntsev
Copy link
Member

asolntsev commented Aug 7, 2018

@CaBocuk I think that different behaviour is a bit confusing, but not critical at all.

BUT

If I modify your sample a bit, we get a real problem. The line below should not throw an exception, but it throws. And this is a bug in Selenide. We need to fix it.

$$("not-existing-locator").first().$$("locator").shouldHave(size(0)); 

// for comparison, the equivalent line for a single web element works fine:
$$("not-existing-locator").first().$("locator").shouldNot(exist);

@Denysss
Copy link
Contributor

Denysss commented Aug 19, 2018

@asolntsev

  1. What do you think about this case?
    $("not-existing-locator").$$("locator").shouldHaveSize(0);
    It throws
    Element not found {not-existing-locator}
    Expected: exist
    NoSuchElementException: Unable to locate element: not-existing-locator
    It's clear and expected as for me.

  2. What is expected behavior for the discussed cases?
    $$("not-existing-locator").first().$$("locator").shouldHave(size(0));
    $$("not-existing-locator").first().$("locator").shouldNot(exist);
    I believe they should throw NoSuchElementException: Unable to locate element: not-existing-locator too.

@asolntsev
Copy link
Member

@Denysss We have two options:

  1. It should throw exception because parent element $("not-existing-locator") doesn't exist.
  2. It should work without errors because collection ("not-existing-locator").$$("locator") IS empty, and ....shouldHaveSize(0) IS true.

I personally think that the 2nd option is better. At least this is consistent with $ behaviour.

Denysss pushed a commit to Denysss/selenide that referenced this issue Oct 14, 2018
@asolntsev asolntsev self-assigned this Oct 28, 2018
@asolntsev asolntsev added this to the 5.0.1 milestone Oct 28, 2018
asolntsev added a commit that referenced this issue Oct 28, 2018
fix #747 IndexOutOfBounds if CollectionElement used ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants