导入了外部的 JAR 包,但仍然出现了“无法解析”的错误。

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

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(&quot;webdriver.chrome.driver&quot;, &quot;C:\\Users\\limje\\JenAutomation\\chromedriver.exe&quot;);  
    	    WebDriver driver=new ChromeDriver();  
    	      
    	// Launch website  
    	    driver.navigate().to(&quot;http://www.google.com/&quot;);  
    	          
    	    // Click on the search text box and send value  
    	    driver.findElement(By.id(&quot;lst-ib&quot;)).sendKeys(&quot;javatpoint tutorials&quot;);  
    	          
    	    // Click on the search button  
    	    driver.findElement(By.name(&quot;btnK&quot;)).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文件 --&gt; 属性 --&gt; 点击应用并关闭

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 --&gt; Properties --&gt; 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>



huangapple
  • 本文由 发表于 2020年4月11日 00:06:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/61144108.html
匿名

发表评论

匿名网友

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

确定