网站开发常用的前端框架,网站演示代码,app开发定制公司如,网站模板怎么引用java做一个toB的客户端操作系统#xff0c;客户端和web的结合#xff1b;
主要是使用java编写客户端代码#xff0c;采用selenium控制浏览器#xff0c;主要是用到selenium自动化测试的功能#xff1b;
javaEE 项目调用 selenium使用谷歌控件chromedriver.exe控制浏览器…java做一个toB的客户端操作系统客户端和web的结合
主要是使用java编写客户端代码采用selenium控制浏览器主要是用到selenium自动化测试的功能
javaEE 项目调用 selenium使用谷歌控件chromedriver.exe控制浏览器打开web网页自动登录后采用socket获取服务端接口自动填写form表单的操作
1、首先新建一个maven项目不需要是springboot项目 引入selenium jar包
dependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdversion3.7.1/version
/dependency
2、引入浏览器驱动 谷歌浏览器驱动下载地址https://chromedriver.storage.googleapis.com/index.html
对应下载版本查看谷歌版本 下载对应版本的驱动放到项目可加载目录下片段
maven打包jar配置
buildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdversion1.3.5.RELEASE/versionconfiguration!-- 指定启动类 --mainClasscom.*.*.*.*.Main/mainClass/configurationexecutionsexecutiongoalsgoalrepackage/goal/goals/execution/executions/plugin/pluginsresourcesresource!--源文件--directorysrc/main/brdriver//directory!--指定编译到META-INF/resources--targetPathbrdriver//targetPath!--指定源文件夹中的哪个资源要编译进行--includesinclude**/*/include/includes/resourceresource!--源文件--directoryimage/directory!--指定编译到META-INF/resources--targetPathimage//targetPath!--指定源文件夹中的哪个资源要编译进行--includesinclude**/*/include/includes/resource/resources/build 加载谷歌浏览器驱动代码片段
import java.net.URL;
import java.net.URLDecoder;import javax.swing.JOptionPane;import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;public class SWBInfoImport {public static WebDriver driver;public static boolean flag true;static {URL url SWBInfoImport.class.getProtectionDomain().getCodeSource().getLocation(); String filePath null; try { filePath URLDecoder.decode(url.getPath(), utf-8);// 转化为utf-8编码 filePathfilePath.substring(0,filePath.lastIndexOf(/)1);} catch (Exception e) { e.printStackTrace(); }System.out.println(filePath);System.setProperty(webdriver.chrome.driver, ./brdriver/chromedriver.exe);driver new ChromeDriver();driver.manage().window().maximize();}public void queryIsIf() {}} javax.swing启动客户端代码片段使用java编辑一个简单的图形界面吧
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;import com.sound.ezaisheng.erp.utils.Tips;public class Major extends JFrame implements ActionListener {/*** */private static final long serialVersionUID -5878629686730451031L;private static final int width 600;private static final int height 300;private JPanel loginPanel;SuppressWarnings(rawtypes)private JComboBox userBox;private JTextField userNameField;private JPasswordField passwordField;private JButton loginButton;private JButton exitButton;public Major(String username) {this.setLayOut(username);this.setSize(Major.width, Major.height);this.setResizable(false);this.setUndecorated(true);this.setVisible(true);int width Toolkit.getDefaultToolkit().getScreenSize().width;int height Toolkit.getDefaultToolkit().getScreenSize().height;this.setLocation((width - Major.width) 1, (height - Major.height) 1);}SuppressWarnings({ serial, rawtypes, unchecked })private void setLayOut(String username) {loginPanel new JPanel(){Overridepublic void paintComponent(Graphics g) {// 双缓冲setDoubleBuffered(true);Image loginImg new ImageIcon(image/major.png).getImage();g.drawImage(loginImg, 0, 0, null);}};loginPanel.setLayout(null);/*userNameField new JTextField();userNameField.setBounds(150, 148, 260, 70);userNameField.setText(您好username);userNameField.setBackground(new Color(34, 41, 56));userNameField.setFont(new Font(宋体, Font.PLAIN, 30) );loginPanel.add(userNameField);*/exitButton new JButton(退出);exitButton.setBounds(445, 242, 100, 32);exitButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Tips.getTips().setLayOut(您真的要退出系统吗, true);}});loginPanel.add(exitButton);this.setContentPane(loginPanel);}/** * 登录按钮监听事件*/public void actionPerformed(ActionEvent e) {}}