I am using one website on which when I update something manually (e.g Update user_name) and getting flash alert which disappear within 5 seconds. But when I automate using selenium the flash alert is not appearing. So My challenge is how to handle / get text from the alert using automation. Tried below approach,
- Captured the complete HTML DOM dump during automation and checked whether the JS alert HTML code is getting or not. >> But in DOM dump I am not able to see that alert code.
- I tried by capturing the video of alert manually and found that the code is displaying on DOM.
- I tried js executor to get the alert text but no luck.
flash_message_text = self.driver.execute_script("document.getElementById('alertFlash').textContent") print(flash_message_text)
My actual code is
def pop_up(self):
self.driver.get("URL")
self.driver.find_element(By.XPATH, "(//button[@class='btn edit-pen login-pass'])[1]").click()
self.driver.find_element(By.XPATH, "//input[@name='v2_user[name]']").clear()
self.driver.find_element(By.XPATH, "//input[@name='v2_user[name]']").send_keys("xyz")
self.driver.find_element(By.XPATH, "//input[@class='btn btn-base1']").click()
flash_message_text = self.driver.execute_script("document.getElementById('alertFlash').textContent")
print(flash_message_text)
screenshot captured manually when alert is appear

