Jishnu Mohanan
Jishnu Mohanan

Reputation: 1

How to find elements in webdriverio cucumber?

How to find elements in webdriverio without id? I have tried $ and $$ to get the elements. But I am getting the browser details.

        ```const text = await browser.$(selector);
        const newText = JSON.stringify(text);
        console.log("Result"+newText);```

[0-0] Result{"sessionId":"4dffe8ace8be04bae87892659187f51e","error":{"error":"no such element","message":"no such element: Unable to locate element: {"method":"css selector","selector":"element"}\n (Session info: chrome=103.0.5060.134)","stacktrace":"Backtrace:\n\tOrdinal0 [0x005A6463+2188387]\n\tOrdinal0 [0x0053E461+1762401]\n\tOrdinal0 [0x00453D78+802168]\n\tOrdinal0 [0x00481880+989312]\n\tOrdinal0 [0x00481B1B+989979]\n\tOrdinal0 [0x004AE912+1173778]\n\tOrdinal0 [0x0049C824+1099812]\n\tOrdinal0 [0x004ACC22+1166370]\n\tOrdinal0 [0x0049C5F6+1099254]\n\tOrdinal0 [0x00476BE0+945120]\n\tOrdinal0 [0x00477AD6+948950]\n\tGetHandleVerifier [0x008471F2+2712546]\n\tGetHandleVerifier [0x0083886D+2652765]\n\tGetHandleVerifier [0x0063002A+520730]\n\tGetHandleVerifier [0x0062EE06+516086]\n\tOrdinal0 [0x0054468B+1787531]\n\tOrdinal0 [0x00548E88+1805960]\n\tOrdinal0 [0x00548F75+1806197]\n\tOrdinal0 [0x00551DF1+1842673]\n\tBaseThreadInitThunk [0x75F5FA29+25]\n\tRtlGetAppContainerNamedObjectPath [0x77837A9E+286]\n\tRtlGetAppContainerNamedObjectPath [0x77837A6E+238]\n"},"selector":"element","parent":{"sessionId":"4dffe8ace8be04bae87892659187f51e","capabilities":{"acceptInsecureCerts":true,"browserName":"chrome","browserVersion":"103.0.5060.134","chrome":{"chromedriverVersion":"103.0.5060.53 (a1711811edd74ff1cf2150f36ffa3b0dae40b17f-refs/branch-heads/5060@{#853})","userDataDir":"C:\Users\HP\AppData\Local\Temp\scoped_dir11904_1068511642"},"goog:chromeOptions":{"debuggerAddress":"localhost:56580"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:credBlob":true,"webauthn:extension:largeBlob":true,"webauthn:virtualAuthenticators":true},"config":{"specs":["./src/features/**/element.feature"],"suites":{},"exclude":[],"outputDir":"H:\work\code\pt\ptwebapp-test\logs","logLevel":"trace","logLevels":{},"excludeDriverLogs":[],"bail":0,"waitforInterval":500,"waitforTimeout":10000,"framework":"cucumber","reporters":["spec"],"services":[["chromedriver",{"logFileName":"wdio-chromedriver.log","outputDir":"driver-logs","args":["--silent"]}],["edgedriver",{"logFileName":"wdio-edgedriver.log","edgeDriverLogs":"./driver-logs","edgeDriverArgs":["--verbose"],"edgeDriverPersistent":true}]],"maxInstances":1,"maxInstancesPerCapability":100,"filesToWatch":[],"connectionRetryTimeout":120000,"connectionRetryCount":3,"execArgv":[],"runnerEnv":{},"runner":"local","specFileRetries":0,"specFileRetriesDelay":0,"specFileRetriesDeferred":false,"reporterSyncInterval":100,"reporterSyncTimeout":5000,"cucumberFeaturesWithLineNumbers":[],"autoCompileOpts":{"autoCompile":true,"tsNodeOpts":{"transpileOnly":true,"project":"tsconfig.json"},"babelOpts":{}},"mochaOpts":{"timeout":10000},"jasmineOpts":{"defaultTimeoutInterval":10000},"cucumberOpts":{"timeout":20000,"backtrace":true,"requireModule":[],"failAmbiguousDefinitions":true,"failFast":false,"ignoreUndefinedDefinitions":false,"names":[],"snippets":true,"source":true,"profile":[],"require":["./src/steps/given.ts","./src/steps/then.ts","./src/steps/when.ts"],"scenarioLevelReporter":false,"order":"defined","strict":true,"tagExpression":"not @Pending","tagsInTitle":false},"onPrepare":[null],"onWorkerStart":[],"onWorkerEnd":[],"before":[],"beforeSession":[null],"beforeSuite":[],"beforeHook":[],"beforeTest":[],"beforeCommand":[],"afterCommand":[],"afterTest":[],"afterHook":[],"afterSuite":[],"afterSession":[null],"after":[],"onComplete":[null],"onReload":[],"beforeFeature":[],"beforeScenario":[],"beforeStep":[],"afterStep":[],"afterScenario":[],"afterFeature":[],"baseUrl":"http://13.232.64.76/#/","_":["run"],"$0":"node_modules\@wdio\cli\bin\wdio.js","config-path":"wdio.conf.ts","ignoredWorkerServices":[],"port":56576}},"isReactElement":false}

Upvotes: 0

Views: 602

Answers (1)

Maverick
Maverick

Reputation: 116

Read the official documentation, it gives pretty good explanation. I would suggest these two:

webdriver.io/docs/selectors

webdriver.io/docs/api/element/$

Upvotes: 0

Related Questions