VSCode包org.openqa.selenium不存在。

huangapple go评论64阅读模式
英文:

VSCode package org.openqa.selenium does not exist

问题

我已经查看了这里的多个问题,其中有答案说selenium JARs需要在项目的依赖项中才能被IDE导入。

但是,我已经在VScode中检查过了,除非我漏掉了什么,所有的selenium JAR文件都在引用的库中提到,因此应该在依赖项中。右键单击项目并打开Java构建路径的旧方法似乎不再起作用。

我仍然收到这个错误消息,说selenium包不存在。

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class App {
    public static void main(String[] args) throws Exception {
        System.setProperty("webdriver.chrome.driver", "~/selenium/testing/bin/chromedriver");
        System.out.println("Hello, World!");
    }
}

如何解决这个问题?我在Linux虚拟机上使用VSC,默认安装在更新的Chromebook上(目前无法获得另一台笔记本电脑)。

感谢您的帮助。

英文:

I have looked through mulitple questions on here which had the answers that the selenium JARs need to be in the project dependencies for the IDE to be able to import.

However, I have checked in VScode and if I ain't missing something, all the selenium JARs are mentioned in the referenced libraries and should be therefore in the dependencies. The old method of right-clicking the project and opening the Java build path doesn't seem to work anymore.

I still get this error message that the selenium package does not exist.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class App {
    public static void main(String[] args) throws Exception {
        System.setProperty("webdriver.chrome.driver", "~/selenium/testing/bin/chromedriver");
        System.out.println("Hello, World!");
    }
}

How can this be fixed? I am using VSC on the Linux virtual machine which is by default installed on the newer chromebooks (can't get another laptop atm)

Thank you for your help.

答案1

得分: 0

自答:

在经过大量研究后,我发现这与Selenium无关,而与Visual Studio Code的Java扩展有关。由于某种原因,如果你启用了扩展"George Fraser的Java语言支持",那么导入Selenium(甚至可能还有其他框架)的任何内容都不起作用。你可以通过错误消息的结尾部分说compiler.err.doesnt.exist来识别这一点。

对于那些读到这篇文章并遇到同样问题的人,你有两个选择:

  1. 象我一样,将其停用 - 使用"红帽的Java语言支持"时似乎没有导入的问题。
  2. 你可以像这个人那样,通过编辑settings.json来解决。

此外,对于那些一直在关注使用Java在Visual Studio Code中设置Selenium的教程的人,这些教程已经非常过时了。如果你按照教程操作,你将始终收到一个NoSuchDriverException,它表示找到了驱动程序,但它是无效的。

解决此问题的方法是删除System.setProperty("插入webdriver名称", "插入外部驱动程序路径")这一行,因为自Selenium版本4.6.发布以来,Selenium会自动下载所需的驱动程序。它还在Selenium库中已经包含了所需的jar文件,因此你可以跳过下载外部web驱动程序(如Chromedriver)的部分。

英文:

Self-answered:

As I found out after doing a ton of research, this has nothing to do with Selenium but with a Java Extension from Visual Studio Code. For some reason, if you have the Extension "Java Language Support by George Fraser" active, importing anything from Selenium (and maybe even more frameworks) won't work. You can recognize this by the error message that says compiler.err.doesnt.exist at the end.

For those of you reading this and having the same problem, you have two options:

  1. Either, like me, deactivate it - there seems to be no problem with imports when using the Java Language Support by Red Hat.
  2. You can approach it the same way as [this person](https://stackoverflow.com/questions/61429146/visual-studio-code-wont-recognize-non-java-imports "editing the settings.json") did, by editing the settings.json.

Apart from that, for those of you who have been following the tutorials for setting up Selenium in Visual Studio Code using Java, the Tutorials are very outdated. If you are following the tutorial, you will always receive a NoSuchDriverException which says that the driver has been found but it is invalid.

The way to fix this is to remove the System.setProperty("[insert webdriver here]", "[insert path to external driver here") line, because since Selenium Version 4.6. came out, Selenium downloads the driver it needs automatically. It also has the required jar files in the Selenium library already, so you can skip the part of downloading external webdrivers like Chromedriver.

huangapple
  • 本文由 发表于 2023年6月12日 00:58:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定