0

I have an application which keeps showing dialog box message to click on continue button Below is code to continue session it keeps coming every minute or so and then which keeps annoying me. so I can work on application without any interruptions. so, I wrote this to automate. it's failing to locate this element and also I tried commented part #EC.alert_is_present() and #browser.switch_to().alert().accept() neither of these two is working for me. however, it logs in without any issues but fails to click on dialog box continue button which keeps coming time to time. please help me with this.

HTML:

<span class="dijitReset dijitInline dijitButtonText" id="confirmInforDialogActionOk_label" data-dojo-attach-point="containerNode">Continue</span>

Code trials:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from datetime import datetime
from selenium.common.exceptions import TimeoutException

browser = webdriver.Chrome(executable_path=r'D:\Jake\Python\chromedriver.exe')
browser.get('https://testtest.com/');
browser.maximize_window()
browser.find_element_by_name('j_username').send_keys('Jake')
browser.find_element_by_name('j_password').send_keys('Jake@123')
browser.find_element_by_xpath("//a[@class='btn btn-primary btn-block']").click()

App_loaded_one = WebDriverWait(browser,180).until (
EC.presence_of_element_located((By.ID, "userAvatarMenu"))
)

def alertpresent():  
    App_loaded = WebDriverWait(browser,300).until (
    #EC.alert_is_present()
    EC.presence_of_element_located((By.ID, 'onfirmInforDialogActionOk_label'))     
    )
    #browser.switch_to().alert().accept()  
    browser.find_elements_by_id('onfirmInforDialogActionOk_label').click()

    print ("Clicked dialog");
    print (datetime.now())

while True:
    alertpresent()

I get this below message in command prompt-

>  DevTools listening on
> ws://127.0.0.1:53745/devtools/browser/59aa8b6e-1dee-458e-afa5-653052f266aa
> Traceback (most recent call last):   File
> "C:\Users\Jake\Desktop\Instances\test.py", line 32, in <module>
>     alertpresent()   File "C:\Users\Jake\Desktop\Instances\test.py", line 22, in alertpresent
>     EC.presence_of_element_located((By.ID, 'onfirmInforDialogActionOk_label'))   File
> "C:\Users\Jake\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py",
> line 80, in until
>     raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jake
  • 65
  • 2
  • 14
  • What does the dialog within the dialog box says? – undetected Selenium Aug 27 '20 at 13:23
  • Can you share HTML of your page or page link. Are you sure its an alert , i am suspecting it could be an iFrame. if so you need to switch to Ifame where button is and then click on it and come back to parent frame. – rahul rai Aug 27 '20 at 13:27
  • Continue – Jake Aug 27 '20 at 13:31
  • @DebanjanB are you asking the HTML source or something else you are pointing out. – Jake Aug 27 '20 at 13:35
  • @rahulrai I am sure it's not alert even i feel, as it doesn't look like any javascript alerts. it's application dialog asking me warning to click on the continue button to stay on page. – Jake Aug 27 '20 at 13:37
  • In that case you need to check this dialog box is present in an iFrame. While in inspection mode you can search for xptah //iframe. See if there is any. See Answer section on how you can switch to frame click and come back to original frame. – rahul rai Aug 27 '20 at 13:55
  • @rahulrai, I searched it does not have iframe. – Jake Aug 27 '20 at 14:32

1 Answers1

0

The element is within a Modal Dialog Box so to click on the element with text as Continue instead of presence_of_element_located() you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.dijitReset.dijitInline.dijitButtonText#confirmInforDialogActionOk_label[data-dojo-attach-point='containerNode']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='dijitReset dijitInline dijitButtonText' and @id='confirmInforDialogActionOk_label'][@data-dojo-attach-point='containerNode']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='dijitReset dijitInline dijitButtonText' and @id='confirmInforDialogActionOk_label'][@data-dojo-attach-point='containerNode']"))).click() --> this worked for me. But third iteration exception came of probably I think I need increase webdriver wait period. also can i use below instead of xpath as above one absolute xpath. WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "onfirmInforDialogActionOk_label")).click() as the xpath provided is absolute xpath which might change. – Jake Aug 27 '20 at 14:59