frame() method is used to switch among frames on the window browser. Also, we can use the defaultContent() method to come back on the default frame's.
Below code is used to switch among frames.
Java API Syntax : WebDriver frame(int index)
WebDriver frame(String frmNameORfrmID)
WebDriver frame(WebElement frmElement)
Code:
Below code is used to switch among frames.
Java API Syntax : WebDriver frame(int index)
WebDriver frame(String frmNameORfrmID)
WebDriver frame(WebElement frmElement)
Code:
import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; public class SwitchFrames { public static void main(String args[]) throws IOException, InterruptedException { WebDriver driver = new FirefoxDriver(); driver.get("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols"); Thread.sleep(10000); Actions action = new Actions(driver); driver.switchTo().frame(0); driver.findElement(By.xpath("html/body/p/strong")).click(); driver.switchTo().defaultContent(); driver.switchTo().frame(1); driver.findElement(By.xpath("html/body/h3")).click(); } }
No comments:
Post a Comment