等待你的幀載入

在很多情況下,你的框架可能不會立即顯示,你可能必須等到它被載入切換。否則你將有 NoSuchFrameException。

因此,在切換之前等待總是一個不錯的選擇。以下是等待幀載入的理想方式。

try{
        new WebDriverWait(driver, 300).ignoring(StaleElementReferenceException.class).
                        ignoring(WebDriverException.class).
                        until(ExpectedConditions.visibilityOf((driver.findElement(By.id("cpmInteractionDivFrame"))));}
    catch{

//只有在你的等待時間 300 秒內看不到你的畫面時才會丟擲異常}