我用的是铬驱动器..。
实用程序
package util;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DriverManager {
public static WebDriver driver;
String baseUrl="http://qmsadm.local";
public DriverManager()
{
System.setProperty("webdriver.firefox.marionette","pathToGeckodriver");
driver=new ChromeDriver();
driver.get(baseUrl);
driver.manage().window().maximize();
}
}控制台错误:
org.openqa.selenium.NoSuchSessionException:没有这样的会话(驱动程序信息: chromedriver=2.10.267518,platform=Linux 4.4.0-47-泛型x86_64) (警告:服务器没有提供任何堆栈跟踪信息)命令持续时间或超时: 84毫秒构建信息:版本:'3.0.1',修订:'1969d75',时间:‘2016-10-1809:49:13-0700’系统信息:主机:'naveen-Inspiron-3542',ip:'127.0.1.1',os.name:'Linux',os.arch:‘amd64 64’,os.version:‘4.4.0-47-泛型’,sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native方法的java.version: 1.8.0_111驱动程序信息: org.openqa.selenium.chrome.ChromeDriver功能{message=unknown错误:未识别的闪烁版本: ed651c97177b2ac846b27f62bb8efed6dac0f90b (驱动程序信息: chromedriver=2.10.267518,platform=Linux 4.4.0-47-通用x86 )_64),platform=ANY}会话ID: c377f4dfc8dbecfa033afa8b8b90995a )( org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635) at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:322) at util.DriverManager(DriverManager.java:19) at client.clientTest.initDriver(clientTest.java:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216) at org.testng.internal.Invoker.invokeConfigurations( org.testng.SuiteRunner.privateRun(SuiteRunner.java:307) at org.testng.SuiteRunner.run(SuiteRunner.java:270) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284) at org.testng.TestNG.runSuitesLocally(TestNG.java:1209) at org.testng.TestNG.runSuites )( org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Methodcom.intellij.rt.execution.application.AppMain.main(AppMain.java:147)测试中的.invoke(Method.java:498)被忽略。===============================================默认套件总测试运行: 1,失败: 0,Skips: 1配置失败: 1,Skips: 1
发布于 2016-12-02 12:31:41
从此链接https://chromedriver.storage.googleapis.com/index.html?path=2.25/下载铬驱动程序并编写如下代码:
public static void setup(){
System.setProperty("webdriver.chrome.driver", "E:\\Selenium \\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
}对我来说很管用
发布于 2019-01-19 06:48:37
为了避免将来出现驱动程序配置问题,可以使用WebdriverManager。在这里阅读完整信息:https://github.com/bonigarcia/webdrivermanager
你可以更换线路
System.setProperty("webdriver.firefox.marionette","pathToGeckodriver");对于WebDriverManager.chromedriver().setup();,这是与平台无关的,并将下载相应的web驱动程序二进制文件,这样以后您就可以省略配置步骤了。
您需要导入WebDriverManger依赖项。
假设您在项目中使用maven。将父<dependencies></dependencies>标记中的下列依赖项添加到pom.xml文件中,
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.2.0</version>
<scope>test</scope>
</dependency>发布于 2016-12-02 07:01:40
在代码中,将pathToGeckodriver替换为Chrome的实际路径。
您的代码需要找到Chrome驱动程序才能集成和执行Chrome驱动程序的位。
路径应该类似于c:\Selenium\chromedriver.exe,意思是Chrome文件的路径。如果不确定只需打开将chromedriver.exe文件放在计算机上的文件夹,请复制资源管理器地址栏中的路径,并在将exe文件粘贴到代码中时将该文件的名称附加到该文件夹中。
对于Ubuntu或任何其他基于Linux的系统,您可以找到chromedriver脚本文件的路径,并在没有.exe扩展的情况下使用该路径。它应该是类似于home/antony/chromedriver或路径的文件夹,无论您在哪个文件夹中都有chromedriver脚本文件。
您可以从这里下载Chrome驱动程序。
https://sqa.stackexchange.com/questions/24019
复制相似问题