簡體   English   中英

如何在 webdriverio cucumber 中查找元素?

[英]How to find elements in webdriverio cucumber?

如何在沒有id的webdriverio中查找元素? 我試過 $ 和 $$ 來獲取元素。 但我得到了瀏覽器的詳細信息。

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

[0-0] 結果{"sessionId":"4dffe8ace8be04bae87892659187f51e","error":{"error":"no such element","message":"no such element: Unable to locate element:{"method":" css 選擇器","selector":"element"}\n (會話信息: 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 [0x0042]\n8C [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 [0x778 37A9E+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 \日志", "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,"req uireModule":[],"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}

閱讀官方文檔,它給出了很好的解釋。 我建議這兩個:

webdriver.io/docs/selectors

webdriver.io/docs/api/element/$

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM