Webdriverio docs have an option to find elements by text, e.g.:
<a href="https://webdriver.io">WebdriverIO</a>
const link = $('=WebdriverIO')
However, when I put $('=WebdriverIO')
in browser console, I am getting:
VM2375:1 Uncaught DOMException: Failed to execute '$' on 'CommandLineAPI': '=WebdriverIO' is not a valid selector.
at <anonymous>:1:1
Why am I getting an error in console even though this selector works in my wdio automated test?
It is throwing error because $ in browser is different to $ in your tests. $ in browser would be jQuery most of time. WebdriverIO doesn't have browser version and it runs on ndoe. Thus "=WebdriverIO" is not a valid JQuery Selector, but a valid webdriverIO selector
If you looking for selectors that works on browser and webdriverIO would be cssSelectors and xpath selector
xpath selector for above is //a[contains(text(),'WebdriverIO']
Open chrome dev console, click on elements tab and press ctrl +F (cmd +F) and search box enter the selector , which then would show the highlighted item