Selenium WebDriver API

来源:互联网 发布:java五种排序算法 编辑:程序博客网 时间:2024/05/22 02:24

1.访问网页,后退,前进,刷新功能

<span style="white-space:pre"></span>WebDriver driver;<span style="white-space:pre"></span>String baseUrl  = "http://www.sogou.com";<span style="white-space:pre"></span>String baseUrl2 = "http://www.baidu.com";<span style="white-space:pre"></span>driver = new FirefoxDriver();<span style="white-space:pre"></span><span style="white-space:pre"></span>driver.navigate().to(baseUrl);<span style="white-space:pre"></span>driver.navigate().to(baseUrl2);<span style="white-space:pre"></span>driver.navigate().back();<span style="white-space:pre"></span>driver.navigate().forward();<span style="white-space:pre"></span>driver.navigate().refresh();<span style="white-space:pre"></span>
2.操作浏览器窗口

/*声明一个Point对象,两个150表示浏览器的位置相对于屏幕左上角的0.0的横坐标和纵坐标的距离*/Point point = new Point(150, 150);/*声明Dimension对象,两个500表示浏览器窗口的长度和宽度*/Dimension dimension =new Dimension(500, 500);/*setPositon方法表示设定浏览器在屏幕上的位置为point对象坐标150,150,在某些浏览器下此方法失效(火狐失败)*/driver.manage().window().setPosition(point);driver.manage().window().setSize(dimension);
//maximazi表示将浏览器窗口最大化<span style="white-space:pre"></span>driver.manage().window().maximize();<span style="white-space:pre"></span>driver.get(baseUrl);


WebElement input = driver.findElement(By.id("text"));//清楚文本框中的默认文字input.clear();
//插入文字<span style="white-space:pre"></span>input.sendKeys("测试内容");


0 0
原创粉丝点击