我有一个网页,上面有一个下载文件的按钮。单击该按钮后,将出现一个模式对话框弹出窗口,其中没有用于“确定”或“取消”的按钮,它只是提示信息对话框,显示“生成debuginfo文件”。请耐心等待。'。在我的ui测试中,我需要检查该对话框的存在。该模态对话框的html代码如下。我应该如何检查对话框的存在?
我尝试使用Alert类并使用Alert(driver).switch_to.alert()
和Alert(driver).dismiss()
和accept()
我也尝试过
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "id_value")))
编辑:已编辑以添加实际代码。
此元素的html代码具有以下参数:
<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>
答案 0 :(得分:-1)
所需元素带有模态对话框,以便找到并提取元素文本生成debuginfo文件。请等待。。您必须为visibility_of_element_located()
引入 WebDriverWait ,并且可以使用以下Locator Strategies中的任何一个:
使用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])
使用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])
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC