SeleniumWebDriver驱动2345浏览器

私下有朋友和同事问我“用Selenium能不能做2345浏览器的自动化操作“。
经过一番研究发现Selenium是基于IE和Chrome内核的,通过“帮助”-“关于”我们可以看到以下信息:
在这里插入图片描述既然是基于Chrome内核,应该可以通过Chrome driver去驱动2345浏览器。此时Chrome内核版本是“69”, 要找到对应版本的ChromeDriver才可以。
通过几次尝试Chromedriver2.38适配这个版本。
下载链接: https://chromedriver.storage.googleapis.com/index.html?path=2.38/

前提准备

下载2.38版本的ChromeDriver并解压到指定文件夹下,此时我解压在:D:\SelfDevelop\Selenium Drivers\2345

代码展示

package com.stone.demos.seleniumdemo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class DemoOf2345 {

	public static void main(String[] args) {
		ChromeOptions options = new ChromeOptions();
		options.setBinary("C:\\Program Files (x86)\\2345Soft\\2345Explorer\\2345Explorer.exe");
		System.setProperty("webdriver.chrome.driver", "D:\\SelfDevelop\\Selenium Drivers\\2345\\chromedriver.exe");
//		options.addArguments("");
		WebDriver chrome = new ChromeDriver(options);
		WebDriverWait wait = new WebDriverWait(chrome, 30);
		
		try {
			//Visit www.sogou.com
			chrome.get("https://www.sogou.com");
			WebElement searchTextBox = wait.until(presenceOfElementLocated(By.cssSelector(".sec-input")));
			WebElement searchButton = wait.until(presenceOfElementLocated(By.cssSelector("#stb")));
			
			//input CSDN
			searchTextBox.clear();
			searchTextBox.sendKeys("CSDN");
			// click search button
			searchButton.click();
			
			// click the first link to CSDN home page
			WebElement theFirstLink = wait.until(presenceOfElementLocated(By.xpath("(//h3[@class='vrTitle'])[1]/a")));
			theFirstLink.click();
			
			assert chrome.getTitle().equalsIgnoreCase("CSDN-专业IT技术社区");
		}finally {
			chrome.quit();
		}
	}

}

代码解释

代码演示的是启动2345浏览器访问搜狗主页,搜索“CSDN”并点击第一个搜索结果

  1. 设置ChromeDriver路径
    System.setProperty(“webdriver.chrome.driver”, “D:\SelfDevelop\Selenium Drivers\2345\chromedriver.exe”);
  2. 设置2345浏览器启动路径
    options.setBinary(“C:\Program Files (x86)\2345Soft\2345Explorer\2345Explorer.exe”);

如果有不懂的地方可以留言提问哦!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值