import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class LoginAndSearch {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Users\\puren\\Downloads\\Compressed\\geckodriver-v0.11.1-win64\\geckodriver.exe");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.linkedin.com");
String a = driver.getTitle();
if (a=="LinkedIn: Log In or Sign Up")
System.out.print("Pass");
else
System.out.println("Fail");
driver.close();
}
}
在此代码中,“If condition”与预期结果不匹配。
答案 0 :(得分:1)
您正在比较String对象的引用。要比较字符串值,请更改代码段,如下所示:
String a = driver.getTitle();
if (a.equals("LinkedIn: Log In or Sign Up"))
System.out.print("Pass");
else
System.out.println("Fail");
点击链接获取更多信息: