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

Polyfill for nth-match CSS 4 selector #891

Closed
Risto-Stevcev opened this issue Nov 21, 2015 · 6 comments
Closed

Polyfill for nth-match CSS 4 selector #891

Risto-Stevcev opened this issue Nov 21, 2015 · 6 comments

Comments

@Risto-Stevcev
Copy link

It would be nice to have the nth-match pseudo-selector polyfill when using WebdriverIO.

In jQuery, this can easily be achieved programatically with something like: $('elem.someclass').eq(2), but it would require using messy xPath in the current version of WebdriverIO, because the nth element of .someclass can't be selected using any other CSS selector except for currently unavailable CSS 4 nth-match.

There's the elements protocol, but there's no way to send the nth element from that to another command.

It would be nice to either have that polyfill like this:

browser.selectByValue('select.comparators:nth-match(2)', 'Some value')

Which could be polyfilled by using the this.elements protocol and selecting the WebElement JSON index from what is asked for in nth-match. If there's no nth-match in the selector, it can just default to it's current behavior and use this.element.

Or something generic and similar to jQuery, which would detect if the selector argument is left out and would attempt to read the result from the previous promise, such as this:

browser.elements('select.comparators').eq(2).selectByValue('Some value')
@christian-bromann
Copy link
Member

Let's also enable :visible and :hidden

@jkwaldrip
Copy link

I'm running into a problem with this right now. Is this issue scoped for any future release?

@christian-bromann
Copy link
Member

@jkwaldrip this wasn't really high on my prio list. Happy to receive PRs for that. You can work around this now by doing:

const comparators = $$('select.comparators');
comparators[2].selectByValue('Some value');

@jkwaldrip
Copy link

@christian-bromann Thanks, I've added an update on #1140 for the issue I was encountering with setValue() in case anyone else runs into it.

@BlueRaja
Copy link

BlueRaja commented Aug 28, 2018

This should probably be closed. nth-match doesn't even exist anymore. It also was never equivalent to jQuery's :eq() selector (which is confusing, which is why it was removed)

Though, getting support for the :eq() selector would be extremely useful..

@christian-bromann
Copy link
Member

agree with @BlueRaja. My workaround above is actually the valid solution. You can also use .filter to limit the selection by arbitrary functions, e.g.

        const results = $$('.commands.property a').filter(function (link) {
            return link.isVisible();
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants