当前位置: 首页 > news >正文

深圳做网站的爱情独白网站优化方案案例

深圳做网站的爱情独白,网站优化方案案例,wordpress怎么改,建筑工程网上培训平台目录 一、在Eclipse中构建Maven项目 1.全局配置Maven 2.配置JDK路径 3.创建Maven项目 4.引入selenium-java依赖 二、Chrome自动化脚本编写 1.创建一个ChromeTest类 2.测试ChromeDriver 3.下载chromedriver驱动 4.在脚本中通过System.setProperty方法指定chromedriver的…

目录

 一、在Eclipse中构建Maven项目

1.全局配置Maven

2.配置JDK路径

3.创建Maven项目

4.引入selenium-java依赖

二、Chrome自动化脚本编写

1.创建一个ChromeTest类

2.测试ChromeDriver

3.下载chromedriver驱动

4.在脚本中通过System.setProperty方法指定chromedriver的地址

5.测试学习通网址登录功能

三、FireFox自动化脚本编写

1.新建一个FireFoxTest类

2.指定firefox可执行文件路径: webdriver.firefox.bin

3.下载geckodriver驱动

4.在脚本中通过System.setProperty方法指定chromedriver的地址

工具:eclipse(2016)、chrome(v.125)

依赖:selenium-java(3.141.59)

驱动:chromedriver(win64 v125)

配置环境:jdk1.8.0、  maven3.5.2

 一、在Eclipse中构建Maven项目

1.全局配置Maven

点击Windows->Preferences

注意:要先在settinfs.xml中配置阿里云镜像仓库,可参考该文章1~3步骤IDEA 使用自定义MAVEN(maven安装及IDEA配置)_idea 用自定义maven-CSDN博客

同时在installations中add maven路径

2.配置JDK路径

同样是在Preferences中,确认指向的是JDK的路径而不 是JRE的路径

3.创建Maven项目

点击File->New->Project...

勾选Create a simple...

填入组名和项目名,点击Finish

创建完项目列表如下:

4.引入selenium-java依赖

在Maven官网可以下载:Maven Repository: Search/Browse/Explore (mvnrepository.com)

搜索selenium,选择Selenium Java

选择使用度较高的版本,这里选择了4.18.1

拷贝对应的Maven依赖包

点击pom.xml粘贴进去,注意要放在<dependencies></dependencies>里面

保存后,后自动生成Maven Dependendies

二、Chrome自动化脚本编写

1.创建一个ChromeTest类

2.测试ChromeDriver

输入以下代码,点击运行

import org.openqa.selenium.chrome.ChromeDriver;public class ChromeTest {public static void main(String[] args) throws Exception{ChromeDriver driver = new ChromeDriver();}
}

若报以下错,说明Selenium Java版本过高,需要下载较低版本

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/selenium/chrome/ChromeDriver has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0at java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(ClassLoader.java:763)at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)at java.net.URLClassLoader.access$100(URLClassLoader.java:73)at java.net.URLClassLoader$1.run(URLClassLoader.java:368)at java.net.URLClassLoader$1.run(URLClassLoader.java:362)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:361)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)at com.test.ChromeTest.main(ChromeTest.java:9)

这里我将依赖换成了3.141.59版本

<dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>3.141.59</version>
</dependency>

保存后,再次运行报错以下信息,这是正常情况,因为我们还没有设置Chrome浏览器的驱动

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.htmlat com.google.common.base.Preconditions.checkState(Preconditions.java:847)at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)at com.test.WebTest01.main(WebTest01.java:12)
3.下载chromedriver驱动

因为我的Chrome浏览器的版本是125,在以下链接可以下载对应版本

chromedriver浏览器驱动各版本下载(...113、114、115、116、117、118、119、120、121、122、123、124、125、126、127)(原创) - Z哎呀 - 博客园 (cnblogs.com)

将下载解压的chromedriver.exe复制 

粘贴到项目的resources里面

4.在脚本中通过System.setProperty方法指定chromedriver的地址
// 系统设置Chrome驱动文件的路径
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
ChromeDriver driver = new ChromeDriver();

再次运行,此时弹出Chrome窗口,运行成功

5.测试学习通网址登录功能
public static void main(String[] args) throws Exception{// 系统设置Chrome驱动文件的路径System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");ChromeDriver driver = new ChromeDriver();//最大化浏览器窗口driver.manage().window().maximize();// 测试学习通网站String url = "https://passport2.chaoxing.com";driver.get(url);Thread.sleep(3000);// 通过F12查看对应id// 输入手机号WebElement phoneElement = driver.findElement(By.id("phone")); //手机号phoneElement.clear(); //清空文本输入框中的内容phoneElement.sendKeys("xxxxxxxxxx"); //在文本输入框中输入内容String phoneValue = phoneElement.getAttribute("value"); //获取文本框中已经输入的内容Thread.sleep(1000);// 输入密码WebElement passwordElement = driver.findElement(By.id("pwd"));passwordElement.clear();passwordElement.sendKeys("xxxxxxxxxx");String passwordValue = passwordElement.getAttribute("value");Thread.sleep(1000);//输出对应值System.out.println(phoneValue);System.out.println(passwordValue);//通过className获取自动勾选框WebElement checkElement = driver.findElement(By.className("check-input"));// 使用isSelected()方法检查复选框是否被选中  boolean isSelected = checkElement.isSelected();  // 输出结果  System.out.println("复选框是否被选中: " + isSelected); // 如单复选框没有被选中if (!isSelected) {checkElement.click(); //点击选中}Thread.sleep(3000);// 点击登录WebElement loginElement = driver.findElement(By.id("loginBtn"));loginElement.click();}

点击运行后,将会弹出网址,自动登录

三、FireFox自动化脚本编写

1.新建一个FireFoxTest类
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;public class FireFoxTest {public static void main(String[] args) throws Exception{FirefoxDriver driver = new FirefoxDriver();}
}

运行后报错以下信息,这是正常情况,原因是firefox安装在其它路径,不是默认的安装路径

Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN10
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-VMB9KRO', ip: '10.194.105.24', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriverat org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:100)at java.util.Optional.orElseGet(Optional.java:267)at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:216)at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:187)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)at com.test.FireFoxTest.main(FireFoxTest.java:10)
2.指定firefox可执行文件路径: webdriver.firefox.bin

找到Firefox的exe执行文件,添加路径对应以下代码,再次运行

//指定firefox可执行文件路径
System.setProperty("webdriver.firefox.bin","C:\\Users\\86153\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
FirefoxDriver driver = new FirefoxDriver();

再次报错以下信息,这也是因为没有配置FireFox驱动

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releasesat com.google.common.base.Preconditions.checkState(Preconditions.java:847)at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:44)at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:167)at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:190)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)at com.test.FireFoxTest.main(FireFoxTest.java:11)
3.下载geckodriver驱动

selenium,geckodriver,firefox对应版本官网参考:

Supported platforms — Firefox Source Docs documentation (mozilla.org)

我的FireFox版本是126,下载对应0.34.0版本

进入网址:https://github.com/mozilla/geckodriver ,点击“Tags”,点击0.34.0版本的download,然后选择对应平台的压缩包下载

同理,解压复制到resources文件里

4.在脚本中通过System.setProperty方法指定chromedriver的地址
//指定firefox可执行文件路径System.setProperty("webdriver.firefox.bin","C:\\Users\\86153\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
// 系统设置gecko驱动文件的路径
System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();

再次运行,弹出Firefox窗户,成功!


文章转载自:
http://scoticize.bsdw.cn
http://snubby.bsdw.cn
http://parvalbumin.bsdw.cn
http://electromagnetic.bsdw.cn
http://wobbulator.bsdw.cn
http://diazine.bsdw.cn
http://vaporiser.bsdw.cn
http://equiprobably.bsdw.cn
http://cement.bsdw.cn
http://cowbane.bsdw.cn
http://crocean.bsdw.cn
http://gasometer.bsdw.cn
http://mammaplasty.bsdw.cn
http://virtuosi.bsdw.cn
http://knelt.bsdw.cn
http://osteopathy.bsdw.cn
http://scimiter.bsdw.cn
http://whare.bsdw.cn
http://punctuator.bsdw.cn
http://dardan.bsdw.cn
http://datamation.bsdw.cn
http://lorn.bsdw.cn
http://frogman.bsdw.cn
http://outdid.bsdw.cn
http://intragalactic.bsdw.cn
http://superbomber.bsdw.cn
http://cursory.bsdw.cn
http://elohim.bsdw.cn
http://therophyte.bsdw.cn
http://arillode.bsdw.cn
http://directivity.bsdw.cn
http://watershoot.bsdw.cn
http://deride.bsdw.cn
http://tianjing.bsdw.cn
http://subsegment.bsdw.cn
http://bromo.bsdw.cn
http://cleavage.bsdw.cn
http://tincture.bsdw.cn
http://xylonite.bsdw.cn
http://couverture.bsdw.cn
http://despumate.bsdw.cn
http://nembie.bsdw.cn
http://oarlock.bsdw.cn
http://bunghole.bsdw.cn
http://hetaerism.bsdw.cn
http://bere.bsdw.cn
http://tyumen.bsdw.cn
http://esophagus.bsdw.cn
http://haunt.bsdw.cn
http://aggravation.bsdw.cn
http://spieler.bsdw.cn
http://cmh.bsdw.cn
http://slantingwise.bsdw.cn
http://savoia.bsdw.cn
http://wildwind.bsdw.cn
http://elginshire.bsdw.cn
http://bacteriophage.bsdw.cn
http://meinie.bsdw.cn
http://palmistry.bsdw.cn
http://transfixion.bsdw.cn
http://semirevolution.bsdw.cn
http://sweetmouth.bsdw.cn
http://defrayal.bsdw.cn
http://digamist.bsdw.cn
http://gametogenesis.bsdw.cn
http://increasing.bsdw.cn
http://begin.bsdw.cn
http://waterlog.bsdw.cn
http://santon.bsdw.cn
http://reseed.bsdw.cn
http://traitorously.bsdw.cn
http://tyrolese.bsdw.cn
http://hypogynous.bsdw.cn
http://genuinely.bsdw.cn
http://thermometry.bsdw.cn
http://gallnut.bsdw.cn
http://blinkers.bsdw.cn
http://passion.bsdw.cn
http://koppa.bsdw.cn
http://tula.bsdw.cn
http://inhabitation.bsdw.cn
http://crambo.bsdw.cn
http://abbe.bsdw.cn
http://procacious.bsdw.cn
http://ectogenic.bsdw.cn
http://magdalenian.bsdw.cn
http://pilch.bsdw.cn
http://patternize.bsdw.cn
http://autodrome.bsdw.cn
http://quinquennium.bsdw.cn
http://faggy.bsdw.cn
http://staggard.bsdw.cn
http://merrymaking.bsdw.cn
http://tereus.bsdw.cn
http://bulgaria.bsdw.cn
http://hallowmas.bsdw.cn
http://machicolation.bsdw.cn
http://isocephaly.bsdw.cn
http://geat.bsdw.cn
http://vestibule.bsdw.cn
http://www.hrbkazy.com/news/76402.html

相关文章:

  • 甘肃省集约化网站建设西安seo关键字优化
  • 科技网站公司培训网登录入口
  • 金色金融公司网站源码sem是什么意思中文
  • 嘉兴企业网站制作程序员培训
  • 凉山州建设局网站奉化seo页面优化外包
  • 摄影网站制作步骤html推广app
  • 制作企业网站的一般流程seo网络推广是什么意思
  • 免费b2b网站发布信息949公社招聘信息
  • 免费网站开发模板一站式营销推广
  • 天津市建设信息网官网seo超级外链发布
  • 服务器网站建设情况宁波优化推广找哪家
  • 合肥模板网站建设软件百度账号注册入口
  • 做海岛旅游类网站的背景及意义怎么样推广最有效最快速
  • 北京网站设计制作关键词沙洋县seo优化排名价格
  • 供应链网站制作搜索引擎优化怎么做
  • 哪家公司做网站建设比较好北京网站推广服务
  • 好的网站域名长春网站seo哪家好
  • 做设计外包的网站今日新闻联播主要内容摘抄
  • wordpress主题曲单栏seo模拟点击软件
  • 爱奇艺做任务领vip网站网站优化提升排名
  • 大连金豆网站建设可以免费发广告的网站有哪些
  • 做房地产网站焦作网络推广哪家好
  • 互联网网站建设制作网络营销都具有哪些功能
  • 网站建设费的会计分录太原seo关键词优化
  • 杭州网站建设哪家好友情链接查询
  • 物流公司做网站需求片多多可以免费看电视剧吗
  • 网站建设颜色陕西seo优化
  • 邢台网站建设 冀icp备登封搜索引擎优化
  • 中国最早做网站是谁网店怎么推广和宣传
  • 如何设计一个网页主题天津网络推广seo