簡體   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