【问题标题】:Chrome opens with "Data;" with seleniumChrome 打开时显示“数据;”含硒
【发布时间】:2016-09-06 16:19:56
【问题描述】:

我是 Selenium 的新手,并试图通过 selenium 驱动程序从 Chrome 打开 localhost:3000 页面。 代码是:

import com.google.common.base.Function;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumTests {

    public static void main(String[] args) {


        System.setProperty("webdriver.chrome.driver", "C://chromedriver_win32//chromedriver.exe");
        WebDriver driver = new ChromeDriver();              
        driver.get("localhost:3000");
    }

}

但是,这会打开我的 chrome 窗口并显示“数据;” . chrome版本是50.0.2661.94

知道具体的问题是什么吗?

【问题讨论】:

  • 如果你手动粘贴到 chrome localhost:3000 会返回什么?
  • 如果有人在使用文件路径时遇到同样的问题,请不要忘记在路径driver.get("file:///path/to/index.html")之前附加“file:///”

标签: google-chrome selenium selenium-webdriver google-chrome-devtools ui-automation


【解决方案1】:

指定您正在使用的协议,所以不要使用localhost:3000,而是使用http://localhost:3000。如果这没有帮助,请参阅 Chromium 问题跟踪器上的评论 here

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。我将 ChromeDriver 更新为 the latest version 并修复了它。

    【讨论】:

    • 你至少可以指出你更新到的版本,所以任何对此感兴趣的人都可以比较。
    • 我正在使用支持 Chrome 版本 55-57 的 Chrome 驱动程序 2.28。下载 Chrome 驱动程序的链接是sites.google.com/a/chromium.org/chromedriver/downloads
    • 对我来说 Chromedriver 版本 2.32 和 chrome 版本 59 工作
    • 看起来他们在 ChromeDriver 88.0.4324.96 中再次修复了它。
    • 如果您在本地以实时模式进行测试,则驱动程序版本应与浏览器版本匹配。有时上游 repo 像 npm 或 brew fall behing,所以以防万一下载最新的here)
    【解决方案3】:

    确保您使用的是latest release of ChromeDriver(目前是 2.28)。我对data:, 有同样的问题。我错误地下载了旧版本并遇到了无法打开指定URL的问题,只是data:,

    【讨论】:

      【解决方案4】:

      是的,它将从数据开始。数据后只是尝试给出 URL。'data:,' URL 只是 chromedriver 在启动 chrome 时导航到的默认地址。因此,这本身并不一定意味着出现任何问题。

      import com.google.common.base.Function;
      import org.openqa.selenium.By;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.WebDriverException;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;
      public class SeleniumTests {
      
      public static void main(String[] args) {
      
      
          System.setProperty("webdriver.chrome.driver", "C://chromedriver_win32//chromedriver.exe");
          WebDriver driver = new ChromeDriver();              
          driver.get("https://www.google.co.in/?gfe_rd=cr&ei=KxAzV8-KEJPT8gfT0IWYAw");
      }
      
      }
      

      它将成功打开。如果您有任何疑问,请回复。快乐学习.. :-)

      【讨论】:

        【解决方案5】:

        我一直在类似的情况下运行,在我的情况下,修复只是将 chrome webdriver 升级到其最新版本(在我的情况下为 V2.27) .

        显示Data; 而不是真正的应用程序 URL 的原因是:

        WebDriver driver = new RemoteWebDriver(new URL("http://<host>:<port>/wd/hub"), desiredCapabilities);
        

        创建失败。相反,driver 对象持有 null 值。

        所以在chrome驱动升级后,它已经正确创建并且问题解决了。

        希望这可以帮助仍然卡住的人!

        【讨论】:

          【解决方案6】:

          如果您使用 Codeception,请使用以下代码开始测试:

          $I-&gt;amOnPage('/');

          【讨论】:

            【解决方案7】:

            你需要添加两个东西来运行:

            首先 - 你应该使用http://localhost:3000

            第二 - 您必须在创建 webDriver 之前使用调试端口:options.addArguments("--remote-debugging-port=9225");

            完整代码:

                WebDriverManager.chromedriver().setup();
                ChromeOptions options = new ChromeOptions();
                options.setExperimentalOption("useAutomationExtension", false);
                options.addArguments("--remote-debugging-port=9225");
                WebDriver driver = new ChromeDriver(options);
            

            如果您有任何疑问,请删除 cmets

            【讨论】:

              【解决方案8】:

              这只是在我使用带有 python 的 selenium 网格时发生的,是由与其他答案建议的不同的东西引起的(至少在我的情况下)。

              事实证明,在创建驱动程序对象(并连接到 chrome)之后但在它被指示导航到 URL 之前引发了运行时异常。这一切都在芹菜任务队列上运行,所以我很容易错过。因此,如果更新 chrome 驱动程序不起作用,请仔细检查您是否正确导航到 URL 并且没有错误等。

              例如:

              driver = webdriver.Remote(
                      command_executor="http://<ip>:4444/wd/hub",
                  )
              
              # a function here raised a runtime exception, causing chrome to launch
              # but sit there with the default URL "data;/"
              
              driver.get("www.google.com")
              

              【讨论】:

                【解决方案9】:

                只需将“chromedriver.exe”替换为latest release of ChromeDriver

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2019-02-14
                  • 1970-01-01
                  • 1970-01-01
                  • 2019-08-22
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多