For switching between frames, use driver.switchTo().frame(). First locate the frame id and define it in a WebElement. Ex:-
WebElement fr = driver.findElementById("id");
Then switch to this frame using this code:-
driver.switchTo().frame("Frame_ID");
This is how it should fially look like:
WebElement fr = driver.findElementById("theIframe");
driver.switchTo().frame(fr);
Then to move to default frame, use:-
driver.switchTo().defaultContent();