<p>元素<kbd>Tout Accepter</kbd>位于<code><iframe></code>内,因此您必须:</p>
<ul>
<li><p>诱导<a href="https://stackoverflow.com/questions/59130200/selenium-wait-until-element-is-present-visible-and-interactable/59130336#59130336">WebDriverWait</a>使所需的<em>帧可用,并切换到它</em></p>
</li>
<li><p>诱导<a href="https://stackoverflow.com/questions/52603847/how-to-sleep-webdriver-in-python-for-milliseconds/52607451#52607451">WebDriverWait</a>使所需的<em>元素可单击</em></p>
</li>
<li><p>您可以使用以下任一<a href="https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890">Locator Strategies</a>:</p>
</li>
<li><p>使用<code>CSS_SELECTOR</code>:</p>
<pre><code>driver.get('http://www.legorafi.fr/')
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"div#appconsent>iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.button filled>span.baseText"))).click()
</code></pre>
</li>
<li><p>使用<code>XPATH</code>:</p>
<pre><code>driver.get('http://www.legorafi.fr/')
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//div[@id='appconsent']/iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'button filled')]/span[contains(@class, 'baseText')]"))).click()
</code></pre>
</li>
<li><p><strong>注意</strong>:您必须添加以下导入:</p>
<pre><code>from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
</code></pre>
</li>
<li><p>浏览器快照:</p>
</li>
</ul>
<p><img src="https://i.stack.imgur.com/bNY23.png" alt="legorafi"/></p>
<hr/>
<h2>参考文献</h2>
<p>您可以在以下内容中找到一些相关讨论:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/53203417/ways-to-deal-with-document-under-iframe">Ways to deal with #document under iframe</a></li>
<li><a href="https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python/44847390#44847390">Switch to an iframe through Selenium and python</a></li>
</ul>