selenuim 日记1
2016-09-07 22:34
113 查看
public class SeleniumAPI {
@Test
public void testIE(){
System.setProperty(“webdriver.ie.driver”, “D:/Mars_WorkSpace/webdrivertest/resource/IEDriverServer.exe”);
WebDriver driver=new InternetExplorerDriver();
driver.get(“http://www.baidu.com“);
}
public class Mytest {
}
@Test
public void testIE(){
System.setProperty(“webdriver.ie.driver”, “D:/Mars_WorkSpace/webdrivertest/resource/IEDriverServer.exe”);
WebDriver driver=new InternetExplorerDriver();
driver.get(“http://www.baidu.com“);
WebElement element=driver.findElement(By.className("task")); //如果没有报异常 List<WebElement> list=driver.findElements(By.className("task")); //如果没有返回null,不报异常 Iterator<WebElement> iter=list.iterator(); while(iter.hasNext()){ iter.next().click(); } } @Test public void test(){ WebDriver driver=new FirefoxDriver(); driver.get("http://localhost:8080"); //driver.navigate().to("http://www.baidu.com"); driver.findElement(By.linkText("新建")).click();; driver.navigate().back(); //driver.quit(); } @Test public void testJs() throws FileNotFoundException{ WebDriver driver=new FirefoxDriver(); driver.get("http://localhost:8080"); JavascriptExecutor js=(JavascriptExecutor)driver; //js.executeScript("",""); //截屏 OutputStream out=new FileOutputStream("D:/test.jpg"); TakesScreenshot take=(TakesScreenshot)driver; File file= take.getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(file, out); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //双击 Actions act=new Actions(driver); WebElement element=driver.findElement(By.id("message")); act.doubleClick(element).build().perform(); //执行拖拽 WebElement src=driver.findElement(By.id("drag")); WebElement dest=driver.findElement(By.id("drop")); act.dragAndDrop(src, dest).perform(); //下拉框列表 WebElement make=driver.findElement(By.id("make")); Select se=new Select(make); List<WebElement> opts =se.getOptions(); Iterator<WebElement> iter=opts.iterator(); se.selectByIndex(0); se.selectByValue("value"); se.selectByVisibleText("honda"); }
}
public class Mytest {
public static void main(String args[]){ FirefoxDriver driver=new FirefoxDriver(); driver.get("http://www.baidu.com/"); driver.findElement(By.id("kw")).sendKeys("selenium"); driver.findElement(By.cssSelector("input[value='百度一下']")).click(); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } driver.quit(); }
}
相关文章推荐
- Selenuim RC + Junit 4 +eclipse 配置 自动化测试
- Selenuim-Python 自动化之安装pip
- CentOS7安装使用selenuim+chrome
- Selenuim & Webdriver - Web UI 测试
- selenuim-webdriver注解之@FindBy、@FindBys、@FindAll的区别
- ubuntu安装使用selenuim&PhantomJS
- Selenuim+Python之元素定位总结及实例说明
- webdrive入门初级脚本练习以及在centos下搭建selenuim+python环境
- selenuim使用js显示控件
- AC日记——小A和uim之大逃离 II 洛谷七月月赛
- selenuim+testng集成ant和reportNG自动执行和发送测试报告
- 关于Selenuim Webdriver查找可能不存在的页面元素的问题
- Selenuim Webdriver notes
- selenuim 2+webdriver+Junit 实现自动化登录
- 手把手教你搭建 Selenuim 自动化环境
- 2017-12-12 Python selenuim(续)
- Selenuim+Python之元素定位总结及实例说明
- 使用selenuim自动操作浏览器
- chrome selenuim 不能以开发者运行的错误
- selenuim学习前记