Asked
4 years, 3 months ago
Viewed
18k times
I’m new to selenium webdriver and java programming. Trying to resolve the error in eclipse 2018-12 «The import org.openqa.selenium.WebDriver cannot be resolved» Im using java 11, selenium standalone server 3.141.59 . Kindly help. I’m unable to import jar files Below is the screenshot
asked Feb 26, 2019 at 0:51
2
As per Can’t compile Java9 module with selenium-java as dependency it seems the Selenium packages can’t be compiled with Java 9 due to split packages and till May 15, 2018 Selenium wasn’t fully compatible with Java 9.
But as per this comment @Jarob22 mentioned, Selenium works just fine using Java 10. Java 9 is already eol and there’s not much point adding extra stuff to try and support just it if 10 works.
But with the landing of e57914a Simon introduced us with basic JPMS support. With this availability (mhomnag/selenium-java10-reproducer@bc63889) now actually builds but you may have to Remove the WebDriverWaiter and just use a sleep for now.
Java 11
As you are using java.version: ‘11.0.1’, selenium-server-standalone-3.141.59.jar is still not compatible with Java 11. But once Java 11 ships and Buck supports it the toolchain witll be rejiged to support Java 11.
Solution
The strategic solution will be to install the latest version of JDK 8u212 and execute the @Tests
answered Feb 26, 2019 at 7:18
3
Chromedriver is located at the same place as this file.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public WebDriver getDriver(final String browser) {
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = null;
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
return driver;
}
error: package import org.openqa.selenium.WebDriver does not exist
error: package org.openqa.selenium.chrome.ChromeDriver
does not exist
I have refered to the link but failed to resolve it
Here is pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.selenium.demo</groupId>
<artifactId>SeleniumMavenDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Asked
4 years, 1 month ago
Viewed
17k times
I’m new to selenium webdriver and java programming. Trying to resolve the error in eclipse 2018-12 «The import org.openqa.selenium.WebDriver cannot be resolved» Im using java 11, selenium standalone server 3.141.59 . Kindly help. I’m unable to import jar files Below is the screenshot
asked Feb 26, 2019 at 0:51
2
As per Can’t compile Java9 module with selenium-java as dependency it seems the Selenium packages can’t be compiled with Java 9 due to split packages and till May 15, 2018 Selenium wasn’t fully compatible with Java 9.
But as per this comment @Jarob22 mentioned, Selenium works just fine using Java 10. Java 9 is already eol and there’s not much point adding extra stuff to try and support just it if 10 works.
But with the landing of e57914a Simon introduced us with basic JPMS support. With this availability (mhomnag/selenium-java10-reproducer@bc63889) now actually builds but you may have to Remove the WebDriverWaiter and just use a sleep for now.
Java 11
As you are using java.version: ‘11.0.1’, selenium-server-standalone-3.141.59.jar is still not compatible with Java 11. But once Java 11 ships and Buck supports it the toolchain witll be rejiged to support Java 11.
Solution
The strategic solution will be to install the latest version of JDK 8u212 and execute the @Tests
answered Feb 26, 2019 at 7:18
3
Chromedriver is located at the same place as this file.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public WebDriver getDriver(final String browser) {
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = null;
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
return driver;
}
error: package import org.openqa.selenium.WebDriver does not exist
error: package org.openqa.selenium.chrome.ChromeDriver
does not exist
I have refered to the link but failed to resolve it
Here is pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.selenium.demo</groupId>
<artifactId>SeleniumMavenDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
LE: I see quite a lot of people are interested in the full-page screenshot, so I thought I might update the answer with some positives (silver bullets).
There are quite a handful of web testing frameworks that can (with minimal setup & effort) produce a full-page screenshot. I come from a NodeJS testing environment, so I can only vouch the following: WebdriverIO & Google’s Puppeteer.
If anyone is interested in an easy way to do it with WebdriverIO, check this answer.
Short answer is NO, YOU CANNOT, if you’re only using Selenium (detailed reason bellow). But, what you can do is make the most out of your device’s(monitor) viewport.
So, start your browser instance (driver) using ChromeOptions()
, which is the method for setting ChromeDriver-specific capabilities. We can do the following:
- maximize the window (using the
--start-maximized
switch); - go full-screen (
F11
-key on Windows,Control+Cmd+F
on Mac, using the--start-fullscreen
switch). - Note: complete list of Chrome command-line-switches can be found here.
Your code should look like this:
// Setting your Chrome options (Desired capabilities)
ChromeOptions options = new ChromeOptions();
options.add_argument('--start-maximized');
options.add_argument('--start-fullscreen');
// Creating a driver instance with the previous capabilities
WebDriver driver = new ChromeDriver(options);
// Load page & take screenshot of full-screen page
driver.get("http://google.com");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Now regarding the full page problem, all drivers (chromedriver
, geckodriver
, IEDriver
, EdgeDriver
, etc.) are implementing the WebDriver W3C standard. Thus, they are dependent on the way the WebDriver team wants to expose the functionality of different features, in our case, ‘Take Screenshot’.
If you read the definition, it clearly states the following:
The Take Screenshot command takes a screenshot of the top-level browsing context’s VIEWPORT.
Legacy-wise, some drivers were able to produce a full-page screenshot (read more about it here), like the old FirefoxDriver, IEDriver, etc. That is no longer the case as they now all implement (to the letter) the WebDriver W3C standard.
testomat.io управление авто тестами
- Python
- Реклама
- Работа
- Консультации
- Обучение
Pat-Legault
What code did you use for chrome?
I’m using a selenium website tutorial and it’s using firefox. There’s a step for using the geckodriver.exe, but that’s not working either.
I’ll use chrome, I just don’t know what all I’d have to change. I imagine the import path along with the = path.
but one other person mentioned the jar files. I’ve followed all instructions to import what’s on my system, but when I see captures of the jar files I should see, my list is much shorter.
So first off, here’s the code I’m using:
package Testing_Pack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class mytestclass {
public static void main(String[] args) {
//set geckodriver path.
System.setProperty(«webdriver.gecko.driver»,»D:Selenium Filesgeckodriver.exe»);
//initialize firefox driver object to open firefox browser.
WebDriver driver = new FirefoxDriver();
//open URL in browser.
driver.get(«http://only-testing-blog.blogspot.in»);
String i = driver.getCurrentUrl();
System.out.println(i);
driver.close();
}
}
And I’ll add a capture of the jar files on my system:
This is one of the pages from the tutorial I’m using:
http://www.software-testing-tutorials-automation.com/2013/09/create-and-run-first-webdriver-script.html
Lastly, I don’t know what version of eclipse is appropriate. I follow the tutorial, but it must be dated, because it wants me to use luna and that’s older, but when I try newer versions, well, the steps to follow are not perfect and I worry that eclipse might be part of the problem.
If anyone can help, I’d appreciate it. I’m a new QA Tester and I need to learn automation for my job.
Alternatively, does anyone have a tutorial or udemy course they know of that has the latest software versions and such? I can follow instructions, but this tutorial I’m using was given to me by a colleague and it’s not seamless.
Я пытался выполнить программу, которая находится на рабочем столе из командной строки:
javac BrowserStackTest.java
Тело программы
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import java.net.URL;
public class BrowserStackTest {
}
и я получил ошибку ниже
BrowserStackTest.java:1: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
^
BrowserStackTest.java:2: error: package org.openqa.selenium does not exist
import org.openqa.selenium.Platform;
^
BrowserStackTest.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
BrowserStackTest.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
^
BrowserStackTest.java:5: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.DesiredCapabilities;
Из-за ошибки я смог заметить, что я не предоставляю jar-файлы для выполнения, но я не могу предоставить из-за отсутствия достаточного количества документации, например, где добавить jar-файлы для выполнения таких программ.
по Вашему совету, сделала теперь такой результат:
«C:Program FilesJavajdk1.8.0_162binjava» -ea -Didea.test.cyclic.buffer.size=1048576 «-javaagent:C:UsersshadoAppDataRoamingJetBrainsIntelliJ IDEA Community Edition 2017.3.3libidea_rt.jar=59328:C:UsersshadoAppDataRoamingJetBrainsIntelliJ IDEA Community Edition 2017.3.3bin» -Dfile.encoding=UTF-8 -classpath «C:UsersshadoAppDataRoamingJetBrainsIntelliJ IDEA Community Edition 2017.3.3libidea_rt.jar;C:UsersshadoAppDataRoamingJetBrainsIntelliJ IDEA Community Edition 2017.3.3pluginsjunitlibjunit-rt.jar;C:UsersshadoAppDataRoamingJetBrainsIntelliJ IDEA Community Edition 2017.3.3pluginsjunitlibjunit5-rt.jar;C:Program FilesJavajdk1.8.0_162jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_162jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_162jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_162jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_162jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_162jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_162jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_162jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_162jrelibextnashorn.jar;C:Program FilesJavajdk1.8.0_162jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_162jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_162jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_162jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_162jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_162jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_162jrelibjce.jar;C:Program FilesJavajdk1.8.0_162jrelibjfr.jar;C:Program FilesJavajdk1.8.0_162jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_162jrelibjsse.jar;C:Program FilesJavajdk1.8.0_162jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_162jrelibplugin.jar;C:Program FilesJavajdk1.8.0_162jrelibresources.jar;C:Program FilesJavajdk1.8.0_162jrelibrt.jar;C:UsersshadoIdeaProjectsAutomation_testingseleniumouttestclasses;C:Usersshado.gradlecachesmodules-2files-2.1junitjunit4.122973d150c0dc1fefe998f834810d68f278ea58ecjunit-4.12.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-java3.8.15b50d4072e0e51779b6e9f3594106312061bfdeselenium-java-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.hamcresthamcrest-core1.342a25dc3219429f0e5d060061f71acb49bf010a0hamcrest-core-1.3.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-chrome-driver3.8.1e147016da4c0e3d37112864ee5905810fe9dae7eselenium-chrome-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-edge-driver3.8.19c2074fad741d2c371a41e4c9d8fe80a43b1956bselenium-edge-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-firefox-driver3.8.15df6c61edd3058b770a9bbde557f7a5ecbb584b4selenium-firefox-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-ie-driver3.8.1a395f99834712925e898b7ec482ffa25db8d84f8selenium-ie-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-opera-driver3.8.1e5f2dd0d77293c6a6f09515095bc9c7f5bb5e947selenium-opera-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-safari-driver3.8.184c83ddd1ec3665770c52733779c2c4b8bd8ed8fselenium-safari-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-support3.8.1a81051b31220c6f4a56d19d35c5cdeb081026dfaselenium-support-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-remote-driver3.8.1f2e493ccd447e36c7bb97bd3d872ed1d7dada6cfselenium-remote-driver-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.seleniumhq.seleniumselenium-api3.8.1248cdab497e53be8a259ac7edea3e82df2aa6cefselenium-api-3.8.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1net.bytebuddybyte-buddy1.7.5baf12b76298eed6a244d9a4de6b5c3baa27ffa0ebyte-buddy-1.7.5.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.apache.commonscommons-exec1.38dfb9facd0830a27b1b5f29f84593f0aeee7773bcommons-exec-1.3.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.apache.httpcomponentshttpclient4.5.3d1577ae15f01ef5438c5afc62162457c00a34713httpclient-4.5.3.jar;C:Usersshado.gradlecachesmodules-2files-2.1commons-codeccommons-codec1.104b95f4897fa13f2cd904aee711aeafc0c5295cd8commons-codec-1.10.jar;C:Usersshado.gradlecachesmodules-2files-2.1commons-loggingcommons-logging1.24bfc12adfe4842bf07b657f0369c4cb522955686commons-logging-1.2.jar;C:Usersshado.gradlecachesmodules-2files-2.1com.google.code.gsongson2.8.23edcfe49d2c6053a70a2a47e4e1c2f94998a49cfgson-2.8.2.jar;C:Usersshado.gradlecachesmodules-2files-2.1com.google.guavaguava23.0c947004bb13d18182be60077ade044099e4f26f1guava-23.0.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.apache.httpcomponentshttpcore4.4.6e3fd8ced1f52c7574af952e2e6da0df8df08eb82httpcore-4.4.6.jar;C:Usersshado.gradlecachesmodules-2files-2.1com.google.code.findbugsjsr3051.3.940719ea6961c0cb6afaeb6a921eaa1f6afd4cfdfjsr305-1.3.9.jar;C:Usersshado.gradlecachesmodules-2files-2.1com.google.errorproneerror_prone_annotations2.0.185f65affce1684999e2f4024983835efc3504012eerror_prone_annotations-2.0.18.jar;C:Usersshado.gradlecachesmodules-2files-2.1com.google.j2objcj2objc-annotations1.1ed28ded51a8b1c6b112568def5f4b455e6809019j2objc-annotations-1.1.jar;C:Usersshado.gradlecachesmodules-2files-2.1org.codehaus.mojoanimal-sniffer-annotations1.14775b7e22fb10026eed3f86e8dc556dfafe35f2d5animal-sniffer-annotations-1.14.jar» com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 MyFirstTest
Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 22081
Only local connections are allowed.
Feb 05, 2018 3:08:13 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=64.0.3282.140)
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.8.1’, revision: ‘6e95a6684b’, time: ‘2017-12-01T18:33:54.468Z’
System info: host: ‘DESKTOP-4D8PS5C’, ip: ‘192.168.0.101’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_162’
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.35.528161 (5b82f2d2aae0ca…, userDataDir: C:UsersshadoAppDataLoca…}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 64.0.3282.140, webStorageEnabled: true}
Session ID: a96e56e854ad69e5b29c12d1e81c99df
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at MyFirstTest.myFirstTest(MyFirstTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Process finished with exit code -1
Итог, брайзер открылся, а тест не прошел
У вас проблема с Selenium на Java. Я пытаюсь следовать примеру на этой странице: http://code.google.com/p/selenium/wiki/GettingStarted
Я набираю это:
$ javac -cp . -cp ~/Downloads/selenium-2.20.0/selenium-java-2.20.0-srcs.jar -cp ~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar -g Example.java
И получив это:
alis-mac-pro:selenium ali$ java ExampleException in thread "main" java.lang.NoClassDefFoundError: Example (wrong name: org/openqa/selenium/example/Example)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Я вставил код из примера в Example.java.
ОБНОВЛЕНИЕ
Добрая душа на #java на irc.freenode.net велела мне привязать мои записи в пути к классам. Итак, вместо:
$ javac -cp . -cp ~/Downloads/selenium-2.20.0/selenium-java-2.20.0-srcs.jar -cp ~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar -g Example.java
Я использовал:
javac -cp .:~/Downloads/selenium-2.20.0/selenium-java-2.20.0-srcs.jar:~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar -g Example.java
Отлично!:-) Но теперь новые ошибки:
Example.java:3: cannot find symbol
symbol : class By
location: package org.openqa.selenium
import org.openqa.selenium.By;
^
Example.java:4: cannot find symbol
symbol : class WebDriver
location: package org.openqa.selenium
import org.openqa.selenium.WebDriver;
^
Example.java:5: cannot find symbol
symbol : class WebElement
location: package org.openqa.selenium
import org.openqa.selenium.WebElement;
^
Example.java:6: package org.openqa.selenium.htmlunit does not exist
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
^
Example.java:13: cannot find symbol
symbol : class WebDriver
location: class org.openqa.selenium.example.Example
WebDriver driver = new HtmlUnitDriver();
^
Example.java:13: cannot find symbol
symbol : class HtmlUnitDriver
location: class org.openqa.selenium.example.Example
WebDriver driver = new HtmlUnitDriver();
^
Example.java:19: cannot find symbol
symbol : class WebElement
location: class org.openqa.selenium.example.Example
WebElement element = driver.findElement(By.name("q"));
^
Example.java:19: cannot find symbol
symbol : variable By
location: class org.openqa.selenium.example.Example
WebElement element = driver.findElement(By.name("q"));
^
8 errors
ОБНОВЛЕНИЕ
Я пробовал:
$ jar tf ~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar
Но я вижу класс org.openqa.selenium.By, например, поэтому я не вижу, что мне не хватает каких-либо пакетов.
ОБНОВЛЕНИЕ
Хорошо!:-) Я удалил спецификатор пакета. Я выполнил:
$ javac -classpath ~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar Example.java
Это то, что дал мне комментатор, за исключением того, что я добавил полный путь к .jar. Затем я выполнил:
$ java -cp .:~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar Example
Который дал мне:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
ОБНОВЛЕНИЕ
Ура! Победа, благодаря Майку Квану. Вот что сработало:
alis-mac-pro:selenium ali$ javac -cp ".:/Users/ali/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar:/Users/ali/Downloads/selenium-2.20.0/selenium-java-2.20.0-srcs.jar:/Users/ali/Downloads/selenium-2.20.0/libs/*" Example.java
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
alis-mac-pro:selenium ali$ java -cp ".:/Users/ali/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar:/Users/ali/Downloads/selenium-2.20.0/selenium-java-2.20.0-srcs.jar:/Users/ali/Downloads/selenium-2.20.0/libs/*" Example
Page title is: Cheese! - Google Search
Кстати, я добавил последнюю часть опции «-cp» (для «libs/*» ), потому что там, где HTMLUnit был, когда я загружал материал Selenium/WebDriver.
ama…@bufetedemarketing.com
unread,
May 4, 2017, 2:32:27 PM5/4/17
to Selenium Users
Hi guys!
I’ve tried to install Selenium Webdriver, with Java, Eclipse, but when I start to do the following code, I get the error: «import org.openqa.selenium.webdriver cannot be resolved»
To configure my Eclipse with Java…
The code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty(«webdriver.firefox.bin»,»C:Program Files (x86)Mozilla Firefox»);
driver = new FirefoxDriver();
String expectedTitle = «Welcome: Mercury Tours»;
// launch Fire fox and direct it to the Base URL
// get the actual value of the title
actualTitle = driver.getTitle();
* compare the actual title of the page with the expected one and print
* the result as «Passed» or «Failed»
if (actualTitle.contentEquals(expectedTitle)){
System.out.println(«Test Passed!»);
System.out.println(«Test Failed»);
// exit the program explicitly
I’ve proved a lot of things but I’m not able to solve it. Anyone knows?
Thanks so much!!
Anish Pillai
unread,
May 5, 2017, 4:18:57 AM5/5/17
to Selenium Users
Hi,
The article you referred is old and the steps have changed. Better approach would be to use the latest version of Selenium and GeckoDriver if you want to run your scripts on Firefox. You can check this article which gives the setup details for the latest versions — Selenium WebDriver 3.4 Setup (specifically points 3 and 4 in the article).
Cheers, Anish
AutomationTestingHub
ama…@bufetedemarketing.com
unread,
May 5, 2017, 11:43:09 AM5/5/17
to Selenium Users
Thanks so much, I resolved with that article!!!
Have a nice day!
SeleniumNewbie
unread,
May 31, 2020, 2:51:29 PM5/31/20
to Selenium Users
Hi Anish,
I’m getting the same issue while using the current latest version of Eclipse v4.15.0 and Java Client & WebDriver bindings v4.0.0.-alpha-6. I’ve added all the files on my Java Build path under Project properties but the issue doesn’t budge. Please help!!
Regards
Selenium Newbie..
Sumit Bhatia
unread,
Jun 17, 2020, 1:57:16 PM6/17/20
to Selenium Users
@Selenium Newbie….did you find a way out? . I am also struggling with the same issue and have tried all .
SeleniumNewbie
unread,
Jun 17, 2020, 4:41:08 PM6/17/20
to Selenium Users
Hey Sumit,
I did find the solution to this problem. Quite a silly one!
Eclipse takes up the highest JavaSE version for execution. Now Java had released JDK-13 earlier and JDK-1.8 just recently.
If you have been using all the latest software releases like me, it is highly probable your Eclipse is also picking up the incorrect version.
No worries!! Just scrap this Java project, create a new one and while setting it up select the correct JavaSE (1.8 in my case) for execution and you should be good to go. Eclipse will set this as default and use it for all your future projects.
Let me know if this worked for you too. Happy Coding!!
Sumit Bhatia
unread,
Jun 26, 2020, 7:43:03 AM6/26/20
to Selenium Users
Thanks a ton @SeleniumNewbee.This has really worked👍👍🙂. Had wasted a lot of time over this.Thanks again!
При запуске webdriver для chrome на IntelliJ он открывает браузер на секунду, затем закрывает с ошибкой. Добавление интервальных ожиданий не помогли.
Код такой:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "c:QASeleniumchromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get ("https://google.com");
}
Вот такая сборка:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
А вот что он мне пишет в консоли:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 29617
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 89
Current browser version is 88.0.4324.104 with binary path C:Program Files (x86)GoogleChromeApplicationchrome.exe
Build info: version: '4.0.0-alpha-7', revision: 'de8579b6d5'
System info: host: 'DESKTOP-62RB6V7', ip: '127.0.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.1'
Driver info: driver.version: ChromeDriver
remote stacktrace: Backtrace:
Ordinal0 [0x00FBE7D3+124883]
Ordinal0 [0x00FBE7B1+124849]
GetHandleVerifier [0x01208688+193832]
GetHandleVerifier [0x01223AC5+305509]
GetHandleVerifier [0x0122021B+291003]
GetHandleVerifier [0x0121E0AC+282444]
GetHandleVerifier [0x01244A90+440624]
GetHandleVerifier [0x012447FC+439964]
GetHandleVerifier [0x0124154B+426987]
GetHandleVerifier [0x01224FFD+310941]
GetHandleVerifier [0x01225D8E+314414]
GetHandleVerifier [0x01225D19+314297]
GetHandleVerifier [0x012E31EC+1089676]
GetHandleVerifier [0x012E17C9+1082985]
GetHandleVerifier [0x012E13A3+1081923]
GetHandleVerifier [0x013DD9FD+2115741]
Ordinal0 [0x0110B82E+1488942]
Ordinal0 [0x010A5A7D+1071741]
Ordinal0 [0x010A559B+1070491]
Ordinal0 [0x010A54B1+1070257]
Ordinal0 [0x010DFF53+1310547]
BaseThreadInitThunk [0x76106359+25]
RtlGetAppContainerNamedObjectPath [0x775B8944+228]
RtlGetAppContainerNamedObjectPath [0x775B8914+180]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$1(ProtocolHandshake.java:126)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:139)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:123)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:501)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:127)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:93)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:163)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:105)
at Main.main(Main.java:12)
Process finished with exit code 1
Заранее спасибо за помощь!!!
Загрузка…
testomat.io управление авто тестами
- Python
- Реклама
- Работа
- Консультации
- Обучение
Get the Reddit app
Log In
Log in to Reddit
Open settings menu
-
Log In / Sign Up
-
Advertise on Reddit