How to handle alertFlash java script alert which is not appear during automation using selenium

25 views Asked by At

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,

  1. 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.
  2. I tried by capturing the video of alert manually and found that the code is displaying on DOM.
  3. 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)

flashAlert image

screenshot captured manually when alert is appear

enter image description here

0

There are 0 answers