当我开始测试时,我在 chrome 地址栏中看到“数据:”,然后什么也没有发生(程序不会继续),而不是开始导航到 url。我正在使用:chrome=55.0.2883.75 chromedriver=2.25 selenium=3.0.1 platform=Win64
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.junit.Assert.assertEquals;
public class MyClass {
public static void main(String[] args) {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver ();
driver.get("http://www.google.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='lst-ib']")).sendKeys("facebook");
driver.findElement(By.cssSelector("input[name='btnK']")).click();
driver.findElement(By.linkText("Facebook - Log In or Sign Up")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.id("u_0_n")));
String expectedTitle = "Facebook - Log In or Sign Up";
assertEquals(expectedTitle,driver.getTitle());
driver.quit();
}
}