Home > front end >  When writing one by one to search field, the letters deleted, how can I fix?
When writing one by one to search field, the letters deleted, how can I fix?

Time:01-02

This method writes the letters of a word one by one to the search field. The reason I do this is because the search query goes for each letter on the backend and the item in the list is listed according to the query. But when using this method, writes the first letter then deletes the first letter instead of typing the second letter. How can I solve this? By the way I don't want to use below logic.Because there was a static delay.

this.searchTxt.type(c,{delay:50})

  async searchOfValue(value:string) {
   await this.page.waitForSelector("//*[contains(@class,'search-input')]", {state:'attached' })
    for (let i = 0; i < value.length; i  ) {
      let c = value.charAt(i);
      await Promise.all([
         this.searchTxt.type(c),
         this.page.waitForLoadState('load')
      ])
    }
  }

Do u have any code suggestions?

CodePudding user response:

async searchOfValue(value: string) {
  await this.page.waitForSelector(
    "//*[contains(@class,'search-input')]",
    { state: "attached" }
  );
  for (let i = 0; i < value.length; i  ) {
    let c = value.charAt(i);
    await this.searchTxt.type(c, {
      delay: 0,
    });
    await this.page.keyboard.down(c);
    await this.page.keyboard.up(c);
    await this.page.waitForLoadState("load");
  }
}

Try like this

  • Related