擅长:python、mysql、java
<p>要访问<code>iframe</code>中的元素,需要首先切换到<code>iframe</code></p>
<p>诱导<code>WebDriverWait</code>()并等待<code>frame_to_be_available_and_switch_to_it</code>(),然后使用以下<code>ID</code>、<code>Name</code>、<code>Xpath</code>或<code>css</code>选择器</p>
<p><strong>ID:</strong></p>
<pre><code>WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"MembersHostFrame")))
</code></pre>
<p><strong>名称:</strong></p>
<pre><code>WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"MembersHostFrame")))
</code></pre>
<p><strong>Xpath</strong>:</p>
<pre><code>WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='MembersHostFrame']")))
</code></pre>
<p><strong>Css选择器:</strong></p>
<pre><code>WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"#MembersHostFrame")))
</code></pre>
<p>您需要导入以下库</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>