zoukankan      html  css  js  c++  java
  • Js代码执行__实现自动化

    一、代码如下

    package www.gui.v2;
    
    import java.awt.AWTException;
    import java.awt.List;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Random;
    import java.util.concurrent.TimeUnit;
    
    import javax.imageio.ImageIO;
    
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;
    
    public class JS {
    	WebDriver driver= null;
    	Actions actions= null;
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		JS gx= new JS();
    		gx.init();
    
    	}
    	
    	private void init() {
    		// TODO Auto-generated method stub
    		// TODO Auto-generated method stub
    		// System.setProperty("webdriver.firefox.bin", "D:\Mozilla
    		// Firefox\firefox.exe");
    		System.setProperty("webdriver.firefox.bin", "D:\FireFox__37\firefox.exe");
    
    		this.driver = new FirefoxDriver();// 启动火狐浏览器
    
    		this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间
    		this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间
    		this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求
    		this.driver.manage().window().maximize();
    		// this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址
    		actions = new Actions(driver);
    		
    		this.driver.get("http://localhost/Agileone/");
    		
    		try {
    			Thread.sleep(3000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    		JavascriptExecutor jse= (JavascriptExecutor)this.driver;
    		String jsContent= "document.getElementById('username').value='admin';document.getElementById('password').value='admin';document.getElementById('login').click();";
    		jse.executeScript(jsContent);
    		
    	}
    	
    	
    
    }
    
  • 相关阅读:
    8-kubernetes-安全
    6-kubernetes网络
    5-kunernetes资源调度
    4-K8S 部署Java应用及应用程序生命周期管理
    3-kubernetes监控与日志管理
    2-K8S常用命令
    1-kubeadm部署1.18.0单master集群
    部署Prometheus+Grafana监控
    微信小程序学习
    vue 中使用 @scroll事件 没有用
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7667866.html
Copyright © 2011-2022 走看看