我试图突出一个元素.请帮我查一下这个代码.(我是nodejs的初学者)
class Utilities {
async highlight(element){
await browser.execute((userelement)=>{
userelement.style.backgroundColor="red";
},element);
}
}
module.exports = new Utilities();
Stepdef:
Utilities.highlight(LoginPage.getusername);
页面对象:
class LoginPage{
get getusername(){
return $('#username');
}
}
错误:
TypeError: elem[prop] is not a function
at \node_modules\@wdio\utils\build\shim.js:253:38
at processTicksAndRejections (node:internal/process/task_queues:96:5)..
详细错误日志(log):
[0-0] 2022-07-18T12:50:08.380Z INFO webdriver: DATA { [0-0] script: 'return ((userelement)=>{\r\n' + [0-0] '
userelement.style.backgroundColor="red";\r\n' + [0-0] '
}).apply(null, arguments)', [0-0] args: [ Promise { } ] [0-0] } [0-0] 2022-07-18T12:50:08.398Z INFO webdriver: RESULT { [0-0] 'element-6066-11e4-a52e-4f735466cecf': 'be8745a8-6499-482b-af98-8dc191b88452' [0-0] } [0-0] Error in "0: When I login with nithildani and asdas123" TypeError: elem[prop] is not a function at C:\Users\nitarula\Documents\Sample2\node_modules@wdio\utils\build\shim.js:253:38 at processTicksAndRejections (node:internal/process/task_queues:96:5) [0-0] 2022-07-18T12:50:08.417Z INFO webdriver: COMMAND deleteSession() [0-0] 2022-07-18T12:50:08.417Z INFO webdriver: [DELETE] http://localhost:9515/session/36ae82293a3b853a2965d478c51f4235 [0-0] 2022-07-18T12:50:08.425Z INFO webdriver: RESULT { [0-0]
'element-6066-11e4-a52e-4f735466cecf': '66da9a07-388f-445c-90ef-9c7a12c29856' [0-0] } [0-0] 2022-07-18T12:50:08.429Z INFO webdriver: COMMAND elementClear("66da9a07-388f-445c-90ef-9c7a12c29856") [0-0] 2022-07-18T12:50:08.429Z INFO webdriver: [POST] http://localhost:9515/session/36ae82293a3b853a2965d478c51f4235/element/66da9a07-388f-445c-90ef-9c7a12c29856/clear [0-0] 2022-07-18T12:50:08.438Z WARN webdriver: Request failed with status 500 due to javascript error: Cannot set properties of undefined (setting 'backgroundColor') [0-0] (Session info: chrome=103.0.5060.114) [0-0] 2022-07-18T12:50:08.439Z INFO webdriver: Retrying 1/3 [0-0] 2022-07-18T12:50:08.439Z INFO webdriver: [POST] http://localhost:9515/session/36ae82293a3b853a2965d478c51f4235/execute/sync [0-0] 2022-07-18T12:50:08.440Z INFO webdriver: DATA { [0-0] script: 'return ((userelement)=>{\r\n' + [0-0] '
userelement.style.backgroundColor="red";\r\n' + [0-0] '
}).apply(null, arguments)', [0-0] args: [ Promise { [Element] } ] [0-0] } [0-0] C:\Users\nitarula\Documents\Sample2\node_modules@wdio\utils\build\shim.js:253 [0-0] return elemprop; [0-0]
^ [0-0] [0-0] TypeError: elem[prop] is not a function [0-0] at C:\Users\nitarula\Documents\Sample2\node_modules@wdio\utils\build\shim.js:253:38 [0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5) { [0-0]
[Symbol(originalCallSite)]: [ CallSite {}, CallSite {} ], [0-0]
[Symbol(mutatedCallSite)]: [ CallSite {}, CallSite {} ] [0-0] } [0-0] FAILED in chrome - C:\Users\nitarula\Documents\Sample2\features\login.feature 2022-07-18T12:50:08.499Z INFO @wdio/cli:launcher: Run onWorkerEnd hook 2022-07-18T12:50:08.502Z INFO @wdio/cli:launcher: Run onComplete hoo
提前感谢