在頁面上搜尋元素。找到的元素將作為特殊的網頁元素物件(具有附加的便利方法)返回。
參數是元素選擇器,可以指定為字串或物件(具有 'selector' 和 'locateStrategy' 屬性)。
可以使用另一個元素作為起點來搜尋元素。
如果多個元素符合定位條件,則只會返回第一個。
用法
browser.element.find(selector)
範例
export default {
demoTest(browser: NightwatchAPI): void {
// Using element function (alias for find).
const button1 = browser.element('button.submit-form');
// Using the find method of the element namespace.
const button2 = browser.element.find('button.submit-form');
// Searching for the icon element inside the .submit-form button.
const icon = button2.find('i');
// Use an object to customise locating behaviour.
const main = browser.element({ selector: 'main', locateStrategy: 'css selector' });
},
async demoTestAsync(browser: NightwatchAPI): Promise<void> {
// button is the WebElement object.
const button = await browser.element('button.submit-form');
}
}
參數
名稱 |
類型 |
描述 |
selector |
字串 | 物件 |
|
返回