【问题标题】:Selenium PHP Chrome Webdriver IssueSelenium PHP Chrome Webdriver 问题
【发布时间】:2013-02-28 08:02:05
【问题描述】:

我正在尝试开始在 Chrome 中使用 Selenium,我之前在处理 Selenium+Firefox 时没有遇到任何问题,但我现在似乎无法启动 Chrome 浏览器 - 每次尝试时,都会出现 Firefox 浏览器。

这是我的设置:

$web_driver = new ChromeDriver("C:\chromedriver\chromedriver.exe");
$session = $web_driver->session('chrome');

我意识到第一行可能不正确。但我想不出还有什么方法可以启动 Chrome。

注意:我已经下载了 chrome 网络驱动程序。

以下是我使用的来源: http://edvanbeinum.com/using-selenium-2-phpunit-to-automate-browser-testing https://code.google.com/p/selenium/wiki/ChromeDriver

非常感谢。

【问题讨论】:

  • 您还使用了哪些其他代码(将其完整发布,或者至少将其精简到尽可能少的行)

标签: php google-chrome selenium


【解决方案1】:

尝试使用

 $session = $web_driver->session('googlechrome');

而不是

 $session = $web_driver->session('chrome');

【讨论】:

    【解决方案2】:

    您可能想看看herehere

    $host = 'http://localhost:4444/wd/hub'; // this is the default
    $capabilities = DesiredCapabilities::htmlUnitWithJS();
    {
      // For Chrome
      $options = new ChromeOptions();
      $prefs = array('download.default_directory' => 'c:/temp');
      $options->setExperimentalOption('prefs', $prefs);
      $capabilities = DesiredCapabilities::chrome(); 
      $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
    }
    $driver = RemoteWebDriver::create($host, $capabilities, 5000);
    

    【讨论】:

    • 单独的代码块并不能提供好的答案。请添加解释(为什么它解决了问题,错误在哪里等等......)
    猜你喜欢
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 2011-12-14
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多