java - Chrome 用 selenium 打开 "Data;"地址

标签 java google-chrome selenium chrome-web-driver

当我开始测试时,我在 chrome 地址栏中看到“data:,”,然后没有任何反应(程序不继续),而不是开始导航到 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();
    }
}

最佳答案

使用新的 ChromeDriver exe (2.26) 进行尝试。下载here 。你可以在notes中看到2.25 应该支持 Chrome 55,但有错误修复,因此请尝试最新版本。

关于java - Chrome 用 selenium 打开 "Data;"地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41077564/

相关文章:

html - 如何在 Google Chrome 检查器中插入 HTML 元素?

amazon-web-services - 如何在 Xvfb 上运行 headless Firefox

javascript - 无法点击元素

java - 在优先考虑源代码保护的情况下加密 JAR

java - 如何在java类中获取图层列表项ID?

javascript - Chrome扩展程序JSON值解析问题

java - 在 Chrome 和 Firefox 中启用 Java 来测试自签名小程序

java - 如何使 listFooter 不可点击

java - 为什么线程对象的wait方法不需要notify方法来唤醒?

java - org.testng.TestNGException : Cannot find class in classpath: testcases. Guru99TestCase1