分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

Js代码执行__实现自动化

发布时间:2023-09-06 01:17责任编辑:沈小雨关键词:暂无标签

一、代码如下

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 stubJS 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 blocke.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);}}

Js代码执行__实现自动化

原文地址:http://www.cnblogs.com/wujianbo123/p/7667866.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved