<p>文本为Ja,ik ga akkoord的元素在<code><iframe></code>内,因此您必须:</p>
<ul>
<li>诱导<em>WebDriverWait</em>,使所需的<em>帧可用,然后切换到</em>。你知道吗</li>
<li>诱导<em>WebDriverWait</em>,使所需的<em>元素可单击</em>。你知道吗</li>
<li><p>您可以使用下列<a href="https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890">Locator Strategies</a>之一:</p>
<ul>
<li><p>使用<code>CSS_SELECTOR</code>:</p>
<pre><code>driver.get("https://www.anwb.nl/");
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src*='anwb']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-decide_link-internal"))).click()
</code></pre></li>
<li><p>使用<code>XPATH</code>:</p>
<pre><code>driver.get("https://www.anwb.nl/");
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src, 'anwb')]")))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@id='accept default level']"))).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></li>
</ul>
<p><a href="https://i.stack.imgur.com/YCwOM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YCwOM.jpg" alt="anwb"/></a></p>
<blockquote>
<p>Here you can find a relevant discussion on <a href="https://stackoverflow.com/questions/53203417/ways-to-deal-with-document-under-iframe">Ways to deal with #document under iframe</a></p>
</blockquote>