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.