1

Suppose I'm need to wait for some result, but there also can appear another results, so in this case I use 2 wait(), but problem is what I can't cancel one wait() if after execution one of them was appeared

Example:

async waitForAction(): Promise<any> {
  try{
    await driver.wait(until.elementLocated(button)); // 1st wait
    await driver.wait(until.elementLocated(unexpectedErr)); // 2nd wait

    await driver.findElement(button).click()

   // how to cancel 2nd wait if 1st appeared 

  } catch(e) {
    console.log(e.message)
  }
}

1 Answers1

1

As far as I know, you can't cancel a wait. One solution would be to combine the button and unexpectedErr locators using an OR operator. Since we don't have the actual locators, I'll give you an example. Let's say button looks like

<button id="submit">

The CSS selector for that would be #submit. Let's say that unexpectedErr looks like

<div class="error">...</div>

The CSS selector for that would be div.error. The OR operator in CSS selector syntax is a comma , so the combined locator would look like.

#submit, div.error

So your method would look like

async waitForAction(): Promise<any> {
  try{
    await driver.wait(until.elementLocated(comboLocator)); // combo wait

    await driver.findElement(button).click()
  } catch(e) {
    console.log(e.message)
  }
}

If you are using XPath, the OR operator* is a pipe character | so the combined locator would look like

//button[@id='submit'] | //div[@class='error']

*Pipe is not really an OR operator in XPath but it will do what you need here. See the XPath-related link in the references below.

References

CSS selector reference

XPath "OR" operator

JeffC
  • 18,375
  • 5
  • 25
  • 47