<p>您可以使用下面的代码打开框架</p>
<pre><code>iframe=driver.find_element_by_id("MemberHostFrame")
driver.switch_to.frame(iframe)
</code></pre>
<p>您可以使用以下代码切换回主窗口:</p>
<pre><code>driver.switch_to.default_content()
</code></pre>
<p>已更新部分以等待出现帧:</p>
<pre><code>wait = WebDriverWait(driver, 20)
wait.until(EC.presence_of_element_located((By.ID, "MemberHostFrame")))
</code></pre>
<p><strong>注意::</strong>::请将以下导入添加到您的解决方案中</p>
<pre><code>from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
</code></pre>
<p><strong>工作代码:</strong></p>
<pre><code>from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r"path for chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("https://members.bet365.com/members/services/host?Microsite=Members&MrsReq=True&DisplayMode=Desktop&prdid=1&platform=1&lng=1&mh=2&ptqs=%2Fhe%2FAuthenticated%2FHistory%2FDisplay%2F%3Frt%3D2%26ht%3D4")
WebDriverWait(driver, 30).until(
EC.presence_of_all_elements_located((By.ID, "MembersHostFrame")))
iframe=driver.find_element_by_tag_name("iframe")
driver.switch_to.frame(iframe)
wait.until(EC.element_to_be_clickable((By.NAME, "ctl00$Main$login$UserName"))).send_keys("Example123")
</code></pre>
<p>输出:</p>
<p><a href="https://i.stack.imgur.com/RAGpf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RAGpf.png" alt="enter image description here"/></a></p>