您可以使用
By.ID
定位器策略,如下所示:
# To switch into the desired IFRAME
iframe = driver.find_element(By.ID, "remote_iframe_0")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(iframe))
# To come out of iframe
driver.switch_to.default_content()
需要进口:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC