2

I have a webpage that has a button to download a file. Once clicking the button there appears a modal dialog popup which has no buttons for 'Ok' or 'Cancel' it is just informative dialog that says 'Generating the debuginfo file. Please wait.'. In my ui testing I need to check for the presence of that dialog. The html code for this modal dialog is as provided below. How should I check the presence of the dialog?

I have tried using Alert class and using Alert(driver).switch_to.alert() and Alert(driver).dismiss() and accept() I have also tried

WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "id_value")))

EDIT: edited to add actual code.

The html code for this element has following parameters:

     <div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-draggable ui-resizable" style="position: fixed; height: auto; width: 400px; top: 143px; left: 555.5px; display: block;" tabindex="-1" role="dialog" aria-describedby="dialog" aria-labelledby="ui-id-1">
      <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
      <span id="ui-id-1" class="ui-dialog-title">Download debug info</span>
      <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" role="button" aria-disabled="false" title="close">
        <span class="ui-button-icon-primary ui-icon ui-icon-closethick">
        </span>
        <span class="ui-button-text">close</span>
      </button>
    </div>
    <div id="dialog" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; max-height: none; height: 177px;">
      <br>Generating the debuginfo file. Please wait.</div>
      <div class="ui-resizable-handle ui-resizable-n" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-w" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-sw" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-ne" style="z-index: 90;">
      </div>
      <div class="ui-resizable-handle ui-resizable-nw" style="z-index: 90;">

  </div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
nd23
  • 83
  • 1
  • 8

1 Answers1

0

The desired element is with a Modal Dialog Box so to locate and extract the element text Generating the debuginfo file. Please wait. you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ui-dialog-content.ui-widget-content#dialog"))).get_attribute("innerHTML").split(">")[1])
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='ui-dialog-content ui-widget-content' and @id='dialog']"))).get_attribute("innerHTML").split(">")[1])
    
  • 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
    Thank you for your response. css_selector method worked for me. However when I use splitlines()[2] I get the error "IndexError: list index out of range" so I used splitlines()[1] and got TimeoutException. Also without using splitlines I got the text returned as:
    Generating the debuginfo file. Please wait. Is there a way to remove
    tag? Last question can we close the dialog when once we have detected it's presence? Currently the dialog is open until the download starts and then test is complete.
    – nd23 May 31 '19 at 15:11
  • 1
    Accepted your answer. Also edited my comment above to include more info about the error. – nd23 May 31 '19 at 15:15
  • @nd23 Checkout the updated answer and let me know the status. – undetected Selenium May 31 '19 at 15:24
  • 1
    Your updated solution worked with a slight change, I tried split(">")[1] instead of index of 2. Thank you. Is there a way to close this modal once we have detected the innerHTML? – nd23 May 31 '19 at 15:41
  • @nd23 Sounds great !!! Can you raise a new question as per your new requirement please? – undetected Selenium May 31 '19 at 15:44