【问题标题】:A beginner : How to identify errors in selenium webdriver [duplicate]初学者:如何识别 selenium webdriver 中的错误 [重复]
【发布时间】:2019-12-24 00:04:08
【问题描述】:

问题是:

1) 在我的简单程序中,如何在运行前识别每一行中的错误?

2) 我把我的程序放在这里,在运行时我遇到了很多错误。我该如何解决?

计划:

package newpackage;

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

public class Myclass {

    public static void main(String[] args) {
        System.out.println("Chrome is selected");
   System.setProperty("webdriver.chrome.driver","C:\\ProgramFiles\\Chrome65.0.3325.146\\googlechromeportable.exe");
        WebDriver driver= new ChromeDriver();

     driver.get("https://www.facebook.com/");
     driver.manage().window().maximize();
     //XPath for Email Field
     driver.findElement(By.xpath("//*[@id='login']")).sendKeys("xxx@gmail.com");
    //XPath for Password Field
     //driver.findElement(By.xpath("//*[@id='pass']")).sendKeys("xxxxxxx");
     driver.findElement(By.xpath("//*[@id=\"u_0_a\"]")).click();
    }

}

错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    WebDriver cannot be resolved to a type
    ChromeDriver cannot be resolved to a type
    By cannot be resolved`enter code here`
    By cannot be resolved

    at newpackage.Myclass.main(Myclass.java:16)

【问题讨论】:

  • 您是否遇到任何其他错误,还是仅此一个?
  • 只有这个

标签: java selenium-webdriver


【解决方案1】:

您需要指定驱动程序位置,您错误地提供了 browser.exe 路径,因此请修改您的代码如下。我的 chromedriverexe 在 Jar_files 文件夹中,您可能需要下载它并将其放在那里。我建议您在编写脚本之前参考博客或视频,以便您获得更清晰的想法。

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;


public class ExecutionbasedOnTReachabilityOfSite {

    WebDriver driver;

    @BeforeClass()
    public void setUp() throws IOException {
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\Jar_files\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        // To start Chrome in Maximized browser window
        options.addArguments("start-maximized");
        // To remove Chrome is being controlled by automated test software
        options.addArguments("disable-infobars");
        driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        }

【讨论】:

    【解决方案2】:

    这是因为您没有在构建路径中添加 selenium-server-standalone-3.141.59.jar 作为依赖项。

    从以下路径下载 JAR: https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar

    右键单击项目文件夹>构建路径>配置构建路径>选择并添加下载的外部JAR

    您遇到的所有编译时错误都将得到解决。

    【讨论】:

    • 谢谢。 JAR 相关错误已得到解决。
    猜你喜欢
    • 2015-05-26
    • 2018-07-30
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多