In quite a few cases your frame might not show up immediately and you probably have to wait till it is loaded to switch. Or else you will have NoSuchFrameException.
So its always a good choice to wait before you switch. Following is a ideal way to wait till a frame is loaded.
try{
new WebDriverWait(driver, 300).ignoring(StaleElementReferenceException.class).
ignoring(WebDriverException.class).
until(ExpectedConditions.visibilityOf((driver.findElement(By.id("cpmInteractionDivFrame"))));}
catch{
// throws exception only if your frame is not visible with in your wait time 300 seconds }