electron-userland / spectron

DEPRECATED: 🔎 Test Electron apps using ChromeDriver
http://electronjs.org/spectron
MIT License
1.68k stars 229 forks source link

error: 'no such element' #1015

Open VijayanRamachandran opened 2 years ago

VijayanRamachandran commented 2 years ago

Hi,

Currently i am facing an issue with Spectron in combination with Mocha.

When i try to get element text using spectron in test case i am facing error "no such element".

Sample.html

image

main.js

image

package.json

"devDependencies": { "electron": "^13.1.6", "mocha": "^9.0.2", "spectron": "^15.0.0" }

SampleTest.js

image

Error

image

Can you help me regarding this ?

Is it problem in my implementation ?

xupea commented 2 years ago

you may misunderstand element id and dom id, and to get the text content from a DOM-element, please refer to getText

oscartbeaumont commented 2 years ago

To clarify @xupea comment, I have put a code sample below.

Use await (await app.client.$("#test")).getText() where app refers to the Spectron Application and #test refers to the element in the DOM with id test (<h1 id="test">Hello World</h1>).