【问题标题】:Nightwatch(PageObject) + TypeScript unable to locate elements using @ symbolNightwatch(PageObject)+ TypeScript无法使用@符号定位元素
【发布时间】:2018-04-24 05:50:06
【问题描述】:

在执行期间,无法使用元素中的 @ 符号链接定位器。

错误:无法使用 xpath 定位元素:“@queryInput”

代码:

import * as config from 'config';
import { NightWatchClient, PageObject } from 'nightwatch';

const pageConfig = config.get<IPageConfig>('pages.google');

const page: PageObject = {
  url: pageConfig.url,
  elements: {
    queryInput: { 
      selector: '//input[@name="q"]',
      locateStrategy: 'xpath'
     }
  },
  commands: [
    {
      enterQuery: (client: NightWatchClient, query: string) => {
        return client
          .waitForElementVisible('//input[@name="q"]', 5000)
          //.setValue('//input[@name="q"]', [query, client.Keys.ENTER])
          .setValue('@queryInput', [query, client.Keys.ENTER])
          .waitForElementVisible('//*[@id="res"]', 5000);
      },
    },
  ]  
};

export = page;

填写code

Link

【问题讨论】:

    标签: javascript typescript automated-tests nightwatch.js pageobjects


    【解决方案1】:

    你不需要传入 nightwatch 客户端。您已经可以在页面对象类中使用this 或this.api。尝试将this 转储到页面对象中的控制台,您将看到所有可用的属性。这适用于 JS,因此它应该在 TS 中以相同的方式工作。

    您可以通过将函数更改为以下内容来使选择器工作:

    enterQuery: (query: string) => {
        return this
          .waitForElementVisible('//input[@name="q"]', 5000)
          .setValue('@queryInput', [query, client.Keys.ENTER])
          .waitForElementVisible('//*[@id="res"]', 5000);
      }
    

    【讨论】:

    • 感谢您的快速回复。由于我是 typescript 和 nightwatch 的新手,因此很难使用 this 或 this.api 关键字进行更改。但我会更新结果。
    • 成功了。感谢您的支持。你能帮我解决以下问题吗stackoverflow.com/questions/50029800/…
    猜你喜欢
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 2021-08-19
    • 2016-07-01
    • 1970-01-01
    相关资源
    最近更新 更多