0

I have a modal dialog which I need to close/dismiss after I have identified it's presence and extracted it's text. The modal comes up when I click on the button to download a file and it says "Generating the debuginfo file. Please wait." This modal is present until the file download starts which is too long depending upon the debuginfo file size. Is there a way to close this dialog and exit with text extracted from it.

I am extracting the text using following code:

downloadText = WebDriverWait(self.driver,40).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ui-dialog-content.ui-widgetcontent#dialog"))).get_attribute("innerHTML").split(">")[1]

Following is the html code for this modal:

     <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
  • There is `Close` associated with `Download debug info`, can you click on that? – supputuri May 31 '19 at 16:25
  • I didn't realize there is a close button. Now I checked it is a cross mark to close the dialog but is hidden. How do I make it visible to close it? – nd23 May 31 '19 at 16:35

2 Answers2

1

Based on the sample code provided in the Original Post, you should be able to close the dialog with the below xpath.

 //span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']

Here is the script to click on the element even if it's not visible.

ele = driver.find_element_by_xpath("//span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']")
driver.execute_script("arguments[0].click();",ele)
supputuri
  • 13,644
  • 2
  • 21
  • 39
0

The close the Modal Dialog Box 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, "button.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-icon-only.ui-dialog-titlebar-close[title='close'] span.ui-button-icon-primary.ui-icon.ui-icon-closethick"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close' and @title='close']//span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']"))).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
  • I used this solution and it worked. But the only issue being that it takes too long until the element is detected to be clickable ~20-25 seconds. Could it be a possibility that element_to_be_clickable() is slow and is there any alternate to it? – nd23 Jun 06 '19 at 13:54
  • @nd23 Working with _Selenium_, follow the _thumb rule_, `click()` should always be invoked inducing _WebDriverWait_, else `click()` may fail with various types of reasons. – undetected Selenium Jun 06 '19 at 13:56