英文:
Imported external jar but still get "Cannot be resolved" errors
问题
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class First {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "C:\\Users\\limje\\JenAutomation\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Launch website
driver.navigate().to("http://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
}
<details>
<summary>英文:</summary>
I imported the external jar under Modulepath, following this [guide][1]. but im missing some if compared with those [2] in the guide. Could it be the reason why im still getting these errors? If thats the case, how can i get those or where can i download individually and import it?
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class First {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "C:\\Users\\limje\\JenAutomation\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
// Launch website
driver.navigate().to("http://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
}
![guide screenshot][2]
![full screen][3]
[1]: https://www.javatpoint.com/selenium-webdriver-installation
[2]: https://i.stack.imgur.com/ReXZW.png
[3]: https://i.stack.imgur.com/wi0c0.png
</details>
# 答案1
**得分**: 1
你遇到这个问题是因为你需要修复你的构建类路径。
一旦你使用右键单击项目添加你的jar文件 --> 属性 --> 点击应用并关闭
2. 从你的项目中移除所有导入的内容,将鼠标悬停在代码 `WebDriver driver = new ChromeDriver();` 上,然后点击修复项目设置。完成后再次将鼠标悬停在Webdriver上,并将库导入到你的解决方案中。
3. 最终你的项目看起来像下面这样,你需要将你的应用程序作为Java应用程序运行。
<details>
<summary>英文:</summary>
You are facing this issue because you need to fix your buld class path.
Once you add your jar files using Right Click on project --> Properties --> Click on apply and close
[![enter image description here][1]][1]
2. Remove all imports from your project and hover over on a code `WebDriver driver = new ChromeDriver();` and click fix project setup. Once done then again hover over on Webdriver and import libraries into your solution.
[![enter image description here][2]][2]
3. Finally your project looks like below and you havee to run your application as an java application
[![enter image description here][3]][3]
[![enter image description here][4]][4]
[1]: https://i.stack.imgur.com/ODcRy.png
[2]: https://i.stack.imgur.com/MZDpx.png
[3]: https://i.stack.imgur.com/jnNJN.png
[4]: https://i.stack.imgur.com/euQJP.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论