擅长:python、mysql、java
<ol>
<li>确保您试图检测的按钮不属于<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe" rel="nofollow noreferrer">inline frame</a></li>
<li>在这种情况下,按钮可能不会立即在<a href="https://www.w3schools.com/js/js_htmldom.asp" rel="nofollow noreferrer">DOM</a>中可用,例如,作为<a href="https://experitest.com/selenium-testing/ajax_technology_selenium/" rel="nofollow noreferrer">AJAX</a>调用的结果,它被添加到主内容之后。因此,一个好的做法是使用<a href="https://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow noreferrer">Explicit Wait</a>,以便让Selenium定期轮询DOM中的元素外观。你知道吗</li>
</ol>
<p>参考代码:</p>
<pre><code>element = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "btn-confirm-yes")))
</code></pre>
<p>您还需要添加以下<a href="https://docs.python.org/3/reference/import.html" rel="nofollow noreferrer">import</a>语句:</p>
<pre><code>from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
</code></pre>