1

I'm working with webdriverIO on a typescript environment, and I'm trying to use the browser.execute function, but typescript keeps identifying the code that I'm writing within the callback function as webdriverIO code and not JS code that needs to be injected to the browser. Here's the function I'm trying to write:

getVisibleElements = selector => {
    const visibleElements = browser.execute(function(selector) { 
        return $(selector).filter((index, el) => $(el).is(':visible'))
    }, selector);
return (visibleElements.value);
}

I get a compilation error on both .filter and .is functions saying the property does not exist on type 'Client>'

If anyone could help me with that I would be really grateful, I haven't found anybody else online with the same problem as me.

1

I suggest use pipeable operators : example

In TypeScript 2.3 and lower, typings will need to be added to functions passed to operators, as types cannot be inferred prior to TypeScript 2.4. In TypeScript 2.4, types will infer via composition properly.

TS 2.3 and under

range(0, 10).pipe(
  map((n: number) => n + '!'),
  map((s: string) => 'Hello, ' + s),
).subscribe(x => console.log(x))

TS 2.4 and up

range(0, 10).pipe(
  map(n => n + '!'),
  map(s => 'Hello, ' + s),
).subscribe(x => console.log(x))
  • Hey, I don't really understand how pipeable operators will help me the problem that I'm facing. The way that i understand, pipeable operators are a way to crate my own operators, so, do you suggest that I will create my own commands for .filter and .is commands and so on? I would be happy of you could expand your solution a little more. – D.Aizenberg Dec 19 '18 at 11:38
  • okay lets take filter() function so what filter means is the operator takes a function predicate as an argument, which returns true if the emitted value meets the criteria, or false otherwise. so lets say that if you want odd numbers out of series of number so how this will done is .filter(x => x%2 === 1) – Rao Dec 19 '18 at 11:55
  • here is an example – Rao Dec 19 '18 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.