簡體   English   中英

無法點擊“關閉”按鈕

[英]Could not click the “Close” button

<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">    
    <div class="ui-dialog-buttonset">
        <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false">
            <span class="ui-button-text">    
                Close    
            </span>
        </button>
    </div>    
</div>

browser.find_element_by_link_text('Close').click()

這是什么按鈕?

您的“關閉”按鈕不是鏈接,而是<span> ,因此請不要使用find_element_by_link_text

你有什么例外? 我假設您有一個'NoSuchElementException',然后沒有看到更多的HTML,就不能為您提供最佳的定位器,因為您可能有更多的跨度,包括文本Close ,凌亂的空格或具有相同類名ui-button許多其他跨度。

但是,請嘗試以下操作(假設您只有一個“關閉”按鈕而沒有混亂的空格):

browser.find_element_by_xpath(".//span[text()='Close']").click()

編輯 :給定的網站是http://earthexplorer.usgs.gov/ ,問題是您有更多的“關閉”按鈕,這些按鈕不可見,因此您需要更好的XPath。

browser.find_element_by_xpath(".//*[@id='notificationArea']/..//span[text()='Close']").click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM