selenium+Java处理frame标签

public class Demo7 {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();

	//获取网页访问路径
	driver.get("file:///C:/Users/Administrator/Desktop/example_frame.html");
	
	//切换到第一个表单中
	driver.switchTo().frame("itcast_frame1");
	
	//切换到第二个表单中
	driver.switchTo().frame("itcast_frame2");
	
	//定位到输入框
	WebElement el = driver.findElement(By.id("sb_form_q"));
	//输入
	el.sendKeys("selenium");
	//点击搜索
	driver.findElement(By.id("sb_form_go")).click();
	
	//定位一个元素,验证已经到达深层表单
	WebElement el_search = driver.findElement(By.id("sb_form"));
	System.out.println("依然在最深层表单");
	
	driver.switchTo().defaultContent();
	try {
		el_search = driver.findElement(By.id("sb_form"));

	} catch (Exception e) {
		System.out.println("已经从表单中退出");
	}
	driver.close();

}
}

猜你喜欢

转载自blog.csdn.net/weixin_38102592/article/details/90204735