量角器在页面中找不到选择器 [英] Protractor cannot find selector in the page

查看:85
本文介绍了量角器在页面中找不到选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

it('should go to summary page without sending the order', async () => {
    stepExecutor.startTimer();
    // redirects, rather than checking logging 
    await stepExecutor.executeStep(loginWithCustomer, {
      name: 'loginWithCustomer',
      description: 'Page: login'
    });
    // 
    await stepExecutor.executeStep(selectFirstSubscription, {
      name: 'selectFirstSubscription',
      description: 'Page: abo first'
    });
});

async function loginWithCustomer() {
  const page = createLoginPage(browser.params.space);
  await page.navigateTo(browser.params.login.url);
  await page.enterLogin(browser.params.login.username, browser.params.login.password);
  await page.redirect(`${browser.baseUrl}${ABO_FIRST_URI}`);
}

async function selectFirstSubscription() {
  const page = new AboFirstPage();
  await page.closeCookieNotification();
  await page.selectFirstSubscription();
}

export class AboFirstPage {
  async selectFirstSubscription() {
    await element(by.css('.button--primary')).click();
  }
}

它给我暴露了一个错误:

It exposes me an error:

- Failed: No element found using locator: By(css selector, .button--primary)

Executed 1 of 1 spec (1 FAILED) in 5 secs.
[18:04:59] I/launcher - 0 instance(s) of WebDriver still running
[18:04:59] I/launcher - chrome #01 failed 1 test(s)
[18:04:59] I/launcher - overall: 1 failed spec(s)
[18:04:59] E/launcher - Process exited with error code 1

但是在它重定向到(函数loginWithCustomer)的页面上,会出现这样的选择器. 和element(by.css('.button--primary'))返回一个对象: 这段代码有什么问题?

But on the page where it makes a redirect to (function loginWithCustomer), such a selector presents. And element(by.css('.button--primary')) returns an object: What can be wrong in this code?

推荐答案

让我们检查等待的问题.将sleep添加到此功能:

Let's check on waiting issue. Add sleep to this function:

async function selectFirstSubscription() {
  const page = new AboFirstPage();
  await page.closeCookieNotification();
  await browser.sleep(5000);
  await page.selectFirstSubscription();
}

如果它可以工作,那么您有等待的问题,在单击元素之前,应添加显式的服务员.例如await ExpectedConditions.elementToBeClickable(element)

If it will work then you have waiting issue and before clicking on element you should add explicit waiter. For example await ExpectedConditions.elementToBeClickable(element)

这篇关于量角器在页面中找不到选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆