【问题标题】:setValue is not a function webdriver io 7setValue 不是函数 webdriver io 7
【发布时间】:2021-10-04 15:45:40
【问题描述】:

我正在尝试使用 webdriver io 7 setValue() 的功能,但我总是收到相同的结果。

我发布我的代码。

这是主页对象

import Page from './page'

class Home extends Page {

    get inputUsername () { return $('#user-name') }
   

    async open () {
        await super.open('https://www.saucedemo.com/')
    }

    async setUser () {
        this.inputUsername.setValue('fakeName')
    }

}

export default new Home()

这是页面对象Page

export default class Page {
   
     open (path) {
         browser.url(path)
    }
}

这是规范

import Home from '../pageobjects/home'

describe('login form', () => {
    it('first login', async () => {
        await Home.open()
        await Home.setUser()

    })
})

这是错误:

TypeError:this.inputUsername.setValue 不是函数

【问题讨论】:

    标签: selenium automation jasmine qa webdriver-io


    【解决方案1】:

    它发生了,因为你必须先await 元素,然后与它交互(在你的情况下设置值)。

    所以,在获取元素之前添加await

     // Home page object
    
     async setUser () {
       //       ⤵ - missed await
       return (await this.inputUsername).setValue('fakeName')
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-25
      • 2021-07-29
      • 1970-01-01
      • 2021-05-15
      • 2011-08-19
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多