我爱编程

selenium中frame处理

2017-03-21  本文已影响0人  红木杉2018

package com.selenium.gen;

import java.io.File;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Frame {

public static void main(String[] args) {

// TODO Auto-generated method stub

WebDriver driver=new FirefoxDriver();

File file=new File("D:/jase/frame.html");

String filePath=file.getAbsolutePath();

driver.get(filePath);

//切换到iframe

// driver.switchTo().frame("if");

WebElement xf=driver.findElement(By.xpath(".//*[@id='if']"));

driver.switchTo().frame(xf);

driver.findElement(By.id("kw")).sendKeys("selenium");

driver.findElement(By.id("su")).click();

//返回上一级表单

driver.switchTo().defaultContent();

driver.quit();

}

}

上一篇 下一篇

猜你喜欢

热点阅读