Spectron と webdriverIO を使用して Electron アプリをテストしています。xpath を使用して要素を見つけようとすると、コンソールにログインすると要素が未定義であると表示されるため、機能しないようです。html コードを以下に示します。
<div class="shadowdiv style-scope bmp-graphs" id="bmsgraphsdiv">
<span class="style-scope bmp-graphs"><a class="style-scope bmp-
graphs">some text</a></span>
</div>
Chrome 開発者ツールからコピーされた Xpath は
//*[@id="bmsgraphsdiv"]/span/a
そして、これを以下のテストコードに入れると(Spectron、Mocha、Chaiを使用)
it('text test', function () {
var text = app.client.element('//*[@id="bmsgraphsdiv"]/span/a');
var innerText = text.innerText;
console.log("text is " + innerText);
return expect(innerText).to.eventually.equal('some text');
});
関数で使用した属性ベースの Xpath が気に入らないようですelement()
。内部テキストは私がテキストを使用しているものの1つであるため、テキストを使用せずに要素を取得できるのはなぜですか、それとも他にありますか?