0

I am a Puppeteer novice and an having difficulty with clicking on the New email button in O365 mail. After I navigate to the site and successfully login, I attempt to click on the New email button (different attempts that all fail are below, commented out along with the latest attempt):

    // await page.waitForXPath('/html/body/div[2]/div/div[3]/div[5]/div/div[1]/div/div[5]/div[1]/div/div[1]/div/div/div[1]/div/button[1]')
    // const newEmailElement = await page.$x('/html/body/div[2]/div/div[3]/div[5]/div/div[1]/div/div[5]/div[1]/div/div[1]/div/div/div[1]/div/button[1]')[0]
    // const newEmailElement = await page.$('._fce_h')
    const newEmailElement = await page.$x("//button[contains(., 'New')]")
    if (newEmailElement) {
      await newEmailElement.click()
    }

This is the failure message:

Error: Execution context was destroyed, most likely because of a navigation.

I thought I could use something from here: Puppeteer Execution context was destroyed, most likely because of a navigation or here: How to click on element with text in Puppeteer but nothing seems to work for this.

This worked in Selenium:

driver.wait(until.elementLocated(By.xpath('/html/body/div[2]/div/div[3]/div[5]/div/div[1]/div/div[5]/div[1]/div/div[1]/div/div/div[1]/div/button[1]')), 30000).click()

Thanks for taking a look.

Jake
  • 33
  • 6
  • This is problematic because: 1) your xPath is too long, it's unmaintainable, try to shorten it as much as you can, absolute xPath is rarely, if ever, a good solution, 2) automating sending emails like this via GUI is brittle in the first place, why don't you use an API? I suppose MS provides something, 3) what does your script do when you debug it? you can at least execute it in non-headless mode with a slower speed and see a bit more, 4) `page.waitForXPath()` doesn't necessarily mean you can interact with the element, or even that the element is visible (if you use it like this). – pavelsaman Dec 14 '20 at 20:02
  • Thanks. Very helpful questions. I have re-tooled it based on the questions you posed and additional research on this topic. As for the reasons for automation, it is part of a larger project and there is not another way/API. Thanks for questioning that though. – Jake Dec 15 '20 at 01:04

0 Answers0