简体   繁体   English

使用硒罐文件时,我在Eclipse中遇到此错误:

[英]I'm getting this error in eclipse while using selenium Jar files:

Following is my simple Java code for selenium : 以下是我简单的selenium Java代码:

package myPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MyClass {

   public static void main(String[] args) {

     System.out.println("My First Selenoium Class");

     WebDriver driver = new FirefoxDriver();
     String baseURL = "http://newtours.demoaut.com";
     String expectedTitle = "Welcome: Mercury Tours";
     String actualTitle = "";

     driver.get(baseURL);
     actualTitle = driver.getTitle();


     if(actualTitle.contentEquals(expectedTitle)){
        System.out.println("Titles are same");
     }
     else {
        System.out.println("Different Titles");
     }

     driver.close();
     System.exit(0);
   }

}

There are 2 errors occuring at the if condition: if条件下发生2个错误:

Error1 : The method contentEquals(StringBuffer) in the type String is not applicable for the arguments (String). 错误1:字符串类型中的方法contentEquals(StringBuffer)不适用于参数(String)。
Error2 : The type java.lang.CharSequence cannot be resolved. 错误2:无法解析类型java.lang.CharSequence。 It is indirectly referenced from required .class files 从所需的.class文件间接引用它

Please help me resolving this. 请帮我解决这个问题。

contentEquals需要一个StringBuffer参数:

StringBuffer expectedTitle = "Welcome: Mercury Tours";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM