繁体   English   中英

Protractor 无法执行点击<li>标签</li>

[英]Protractor can't perform click on <li> tag

我正在尝试对我的应用程序进行 e2e 测试,但我无法在搜索引擎上执行点击操作。 这是我想尝试“单击”第一个元素但 protractor 卡在下图中的示例:

在此处输入图像描述

我正在谈论的网站是: https://rent.decathlon.it/

结果是超时错误,因此没有单击该元素。

这是 protractor 代码:

import { AppPage } from './app.po';
import {browser, by, element, logging} from 'protractor';
import {SearchBoxWizard} from '../elements/searchbox_wizard';

describe('workspace-project App', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  it('shoud open select item', async () => {
    await page.navigateTo();
    browser.sleep(500);
    const searchBoxWizardElements = new SearchBoxWizard();
    await searchBoxWizardElements.getLocationInput().click();
    await searchBoxWizardElements.getLocationInput().clear();
    await searchBoxWizardElements.getLocationInput().sendKeys('Milano');
    await browser.sleep(500);
    element(by.css(`.autocomplete-search > ul > li:nth-child(1) > span`)).click();
  });

  afterEach(async () => {
    // Assert that there are no errors emitted from the browser
    const logs = await browser.manage().logs().get(logging.Type.BROWSER);
    expect(logs).not.toContain(jasmine.objectContaining({
      level: logging.Level.SEVERE,
    } as logging.Entry));
  });
});

有人知道为什么吗?

我正在使用这个堆栈:

  • Angular 8
  • protractor 5.6 或 7
  • 业力 4.1
  • 茉莉花 3

问候

编辑

我注意到非常奇怪的行为,如果我检查是否显示正文,protractor 看不到它,这是代码......

  it('shoud open select item', async () => {
    await page.navigateTo();
    const searchBoxWizardElements = new SearchBoxWizard();
    const cookiePolicy = new CookiePolicy();
    await cookiePolicy.getAcceptCta().click();
    await searchBoxWizardElements.getLocationInput().click();
    await searchBoxWizardElements.getLocationInput().clear();
    await searchBoxWizardElements.getLocationInput().sendKeys('Milano').then(
      async _ => {
        await browser.sleep(2500);
        await element(by.css('body')).isDisplayed();
      });
  });

我认为这类似于“失去”应用程序焦点......我不知道......

你有什么想法吗?

问候

  1. 它绝对是谷歌 api。 我检查了那个。 请求从https://maps.googleapis.com/maps/api/place/js返回
  2. 你在很多地方都错过了await 您需要阅读有关承诺和处理方式的内容是await

browser.sleep需要await

.click()需要await

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM