<p>由于所需元素位于<code><iframe></code>内,因此要在元素上调用<code>click()</code>,您必须:</p>
<ul>
<li>为所需的<code>frame_to_be_available_and_switch_to_it()</code>诱导<em>WebDriverWait</em></李>
<li>为所需的<code>element_to_be_clickable()</code>诱导<em>WebDriverWait</em></李>
<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>WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#content-frame")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-qa='reporting-filter-trigger-toggle'][data-ember-action]"))).click()
</code></pre></li>
<li><p>使用<code>XPATH</code>:</p>
<pre><code>WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='content-frame']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-qa='reporting-filter-trigger-toggle' and @data-ember-action]"))).click()
</code></pre></li>
</ul></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>
</ul>
<hr/>
<h2>参考文献</h2>
<p>您可以在以下内容中找到一些相关讨论:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/47993443/selenium-selenium-common-exceptions-nosuchelementexception-when-using-chrome/47995294#47995294">Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome</a></li>
<li><a href="https://stackoverflow.com/questions/53203417/ways-to-deal-with-document-under-iframe">Ways to deal with #document under iframe</a></li>
</ul>