zoukankan      html  css  js  c++  java
  • selenium 学习笔记 ---新手学习记录(6) 问题总结(java)

    1.查看网页的cookie信息

    1  //查看cookie 登录后的cookie
    2         Set<Cookie> setcoke= driver.manage().getCookies();
    3         for(Cookie str: setcoke){
    4             System.out.println("cookie="+str);
    5         }
     for(Iterator<Cookie> iterator = setcoke.iterator();iterator.hasNext();){  
                System.out.print(iterator.next()+" ******");  
            }
    

     2.测试数据参数化,数据库,批量化,同时set集合的读取和使用

    //测试数据参数化测试
    @Test(enabled=true,dataProvider="datas",timeOut=120000,dataProviderClass=dlTest.class)
    public void dlTest_6(String users,String pass) throws InterruptedException{
    	    driver=bmm.Login(users, pass, 0);
    	    System.out.println("users="+users);
    	    //查看cookie 登录后的cookie
    	    Set<Cookie> setcoke= driver.manage().getCookies();
    	    for(Cookie str: setcoke){
    	    	System.out.println("cookie="+str);
    	    }
    	    /* //查看cookie
    	    for(Iterator<Cookie> iterator = setcoke.iterator();iterator.hasNext();){  
                System.out.print(iterator.next()+" ******");  
            } */
    		String str_dlemail1=driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div")).getText();
    		System.out.println("dlTest_6实际结果:"+str_dlemail1);
    		Assert.assertEquals("登录成功", str_dlemail1);
    }
    //登录数据等同记事本
    @DataProvider
    public static  Object[][] datas(){
    	return new Object[][]{
    			new Object[]{"test@qq.com","123456"},
    			new Object[]{"test1@qq.com","123456"},
    	};
    }
    

     3.invocationCount代表执行次数,timeOut超时时间设置

    @Test(enabled = false,invocationCount=1)

    4.等待元素加载完成后,在继续执行。

    WebDriverWait wait = new WebDriverWait(driver,100);  
    wait.until(new ExpectedCondition<WebElement>(){  
                @Override  
                public WebElement apply(WebDriver d) {  
                    return d.findElement(By.xpath("html/body/div[1]/div/div/div/form/table/tbody/tr[12]/td[2]/div/div/img"));  
                }});  

    封装成函数后为:

    	 /**
    	  * 等待元素出现后再执行
    	  * 也就是等待元素对象加载完成
    	  * driver驱动,By对象
    	  * return 元素对象
    	  * */
    public WebElement  ElementFinish(WebDriver driver,By by ){
    	 WebDriverWait wait = new WebDriverWait(driver,100);  
         return wait.until(new ExpectedCondition<WebElement>(){  
               @Override  
               public WebElement apply(WebDriver d) {  
                   return  d.findElement(by);  
               }}); 
    }
    

     5.操作js代码

       //控制滚动条 下拉到最后 把滚动条下拉到最后,

     String high="scroll(0,10000);";
     ((JavascriptExecutor)driver).executeScript(high);
    

     6.判断元素是否存在

    WebElement linkUsername = driver.findElement(By.xpath("//a[contains(text(),"+username+")]"));

    return linkUsername.isDisplayed();
     
    这一方法的前提是:该元素之前已经存在,仅仅需要判断是否被显示。
  • 相关阅读:
    抽样调查
    一次项目上线发布的感想
    Nginx failing to load CSS and JS files (MIME type error)
    securecrt-active
    golang-http-post
    remove-weknow-ac from mac chrome
    批量写入redis
    golang 修改数组中结构体对象的值的坑
    golang使用json生成结构体
    json定义
  • 原文地址:https://www.cnblogs.com/kllay/p/5207458.html
Copyright © 2011-2022 走看看