ウェブ要素のインスタンスを比較するために、あなたはelement(...).getId()
によって返される値をテストすることができます。
返されたIDは、ページ内に遭遇するHTMLElement
オブジェクトごとに生成された参照であり、id属性/プロパティとは関係ありません。
これは、コンテンツをスクロールして最後の要素を交換するのを待つための例です:
browser.get("https://twitter.com/BBC/");
// define the locator for the last element
var lastElement = $$('#stream-items-id > li').last();
// store the reference for the last element
var storedRef = lastElement.getId();
// scroll to the last element
browser.actions().mouseMove(lastElement).perform();
// wait for the last element to be another reference
browser.wait(function(){
return storedRef.then(function(a){
return lastElement.getId().then(b => a !== b);
}, 3000);
});
// compare the stored reference with the last element
expect(lastElement.getId()).not.toEqual(storedRef);
は、代わりに読み取り、テキストの直接要素オブジェクトを比較することはできませんか? – Manya
@Manyaこれで何をしたいですか?分度器のWeb要素には、セレクタや実行可能な関数のリストなど、いくつかの静的な要素が含まれていますが、これらはすべて、呼び出されたときに実行される約束を解決します。その関数の結果は、一般的にはオブジェクト自体ではなく、通常有用です。 – user2020347