在python中使用selenium关闭模式

svmlkihl  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(406)

一段时间以来,我一直试图关闭一个模式,但不知怎么的,没有任何效果。
我最后尝试的是执行js脚本。如果我在浏览器控制台中执行它,而不是在selenium中执行,它就可以工作。
我用过: driver.execute_script("document.getElementById('btnChiudi').click() 结束:

<div id="ctl00_mainCopy_upMsgFePa">
                <div tabindex="-1" id="Modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLabel">
                                    <span class=" glyphicon glyphicon-info-sign"><input type="image" name="ctl00$mainCopy$CustomImageButton1" id="ctl00_mainCopy_CustomImageButton1" disabled="disabled" src="" style="border-width:0px;"></span>
                                    <span id="ctl00_mainCopy_Label1">Avviso</span></h5><button type="button" class="btn--close close" data-dismiss="modal" aria-label="Close" id="btnCloseX" onclick="$get('btnChiudi').click()">
                                    <span aria-hidden="true">×</span></button></div><div class="modal-body">
                                <center>
                                    <span id="ctl00_mainCopy_msgAttenzioneFePa" style="display:inline-block;border-width:0px;border-style:None;font-size:11pt;width:97%;text-align: left">TEXT<ul id="ctl00_mainCopy_blListConvInComp" style="text-align: left; padding-left: 25px;"><li>TEXT</li></ul>TEXT</span><table id="ctl00_mainCopy_TblElencoConvenzioniSenzaSceltaFePa" width="100%">
                                    <tbody><tr>
                                        <td>&nbsp; </td>
                                    </tr>
                                    <tr>
                                        <td>
                                             <ul id="ctl00_mainCopy_blListConvInComp" style="text-align: left; padding-left: 25px;">
                                                  <li>SSP00703052</li>
                                             </ul>
                                        </td>
                                    </tr>
                                    </tbody></table>
                                </center>
                            </div>
                            <div class="modal-footer">
                                <input type="submit" name="ctl00$mainCopy$btnChiudi" value="Chiudi" id="btnChiudi" class="btn btn--secondary" data-dismiss="modal">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

情态动词

wgx48brx

wgx48brx1#

您可能希望尝试使用下面的xpath,并显式等待,如下所示:
xpath:

//input[@id='btnChiudi']/..

代码:

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='btnChiudi']/.."))).click()

进口:

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

相关问题