标签: ghostdriver

使用 PhantomJS + Selenium 处理重定向

我目前通过 PhantomJS + Selenium 在 Python 中运行浏览器测试。

desired_capabilities = dict(DesiredCapabilities.PHANTOMJS)
desired_capabilities["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36")
driver = webdriver.PhantomJS(executable_path="./phantomjs", desired_capabilities=desired_capabilities)
driver.get('http://google.com')
Run Code Online (Sandbox Code Playgroud)

这工作正常,除非我尝试的页面get有重定向。

例子:

https://login.vrealizeair.vmware.com/
Run Code Online (Sandbox Code Playgroud)

在这种情况下,get无法正常工作。页面源为空:<html><head></head></body></html>

这是发布的解决方案中的一个已知问题,涉​​及添加一段代码以正确处理重定向。

如果您使用 Selenium 运行测试(在我的第一个代码片段中),如何/在哪里添加此代码?它是 的一部分吗desired_capabilties

例子:

page.onNavigationRequested = function(url, type, willNavigate, main) {
    if (main && url!=myurl) {
        myurl = url;
        console.log("redirect caught")
        page.close()
        renderPage(url);
    }
};

page.open(url, function(status) {
    if (status==="success") {
    console.log(myurl);
        console.log("success")
            page.render('yourscreenshot.png'); …
Run Code Online (Sandbox Code Playgroud)

python phantomjs selenium-webdriver ghostdriver

5
推荐指数
1
解决办法
3771
查看次数

如何在测试失败时使用PHPUnit和Selenium2捕获屏幕截图?

我正在使用PHPUnit 4.6和PHPUnit Selenium 1.4.2与PhantomJS.当selenium测试失败时,我想捕获最后一页的截图.在PHPUnit Manual中有一个Selenium 1的例子,但我正在尝试使用Selenium 2,因为我需要使用GhostDriver.

WebTestCase.php

class WebTestCase extends PHPUnit_Extensions_Selenium2TestCase
{
    protected $captureScreenshotOnFailure = TRUE;
    protected $screenshotPath = '/../../screenshots';
    protected $screenshotUrl = 'http://localhost:8080/screenshots';

    protected function setUp() {
        $this->setBrowser('phantomjs');
        $this->setBrowserUrl("http://localhost:8080");
        $this->setHost('localhost');
    }
}
Run Code Online (Sandbox Code Playgroud)

test.php的

class Test extends WebTestCase
{

    public function testTitle()
    {
        $this->url('');
        assertEquals($this->title(), "My App");
    }
}
Run Code Online (Sandbox Code Playgroud)

但这不是截图.

$ vendor/bin/phpunit 
PHPUnit 4.6-ge85198b by Sebastian Bergmann and contributors.

Configuration read from /MyApp/phpunit.xml

F

Time: 231 ms, Memory: 5.50Mb

There was 1 failure:

1) Test::testTitle
Failed asserting …
Run Code Online (Sandbox Code Playgroud)

testing selenium phpunit phantomjs ghostdriver

4
推荐指数
2
解决办法
4165
查看次数

如何在使用GhostDriver时设置屏幕/窗口大小

我在基于Java的项目中使用GhostDriver作为WebDriver实现.我想拍摄页面的快照.默认页面大小有点笨拙,所以我想控制快照的页面大小.但是,我找不到谷歌的任何例子.那么,有人可以告诉我怎么样?非常感谢你.

java selenium phantomjs selenium-webdriver ghostdriver

3
推荐指数
1
解决办法
6361
查看次数

如何用java将语言设置为PhantomJs Ghostdriver?

我正在使用PhantomJs Ghostdriver和Java来获取网页的一些截图.我的问题是PhantomJs正在使用主机的语言环境,所以我需要设置默认语言.我已经找到了如何为Chrome驱动程序和Firefox执行此操作,但无法找到Ghostdriver的解决方案.

任何提示?

java selenium phantomjs selenium-webdriver ghostdriver

3
推荐指数
1
解决办法
2351
查看次数

使用Ruby在Selenium Webdriver中为PhantomJS设置自定义用户代理

我今晚一直在网上,现在大约3-4个小时.我已经尝试过每一个我遇到过的建议.我甚至检查了Selenium驱动程序对象上的"capabilities"对象,以确保它实际设置在那里,实际上它是:

#<Selenium::WebDriver::Remote::Capabilities:0x00000007475cf0
 @capabilities=
  {:browser_name=>"phantomjs",
   :version=>"1.9.7",
   :platform=>:"linux-unknown-64bit",
   :javascript_enabled=>true,
   :css_selectors_enabled=>true,
   :takes_screenshot=>true,
   :native_events=>true,
   :rotatable=>false,
   :firefox_profile=>nil,
   :proxy=>#<Selenium::WebDriver::Proxy:0x00000007475908 @type=:direct>,
   "driverName"=>"ghostdriver",
   "driverVersion"=>"1.1.0",
   "handlesAlerts"=>false,
   "databaseEnabled"=>false,
   "locationContextEnabled"=>false,
   "applicationCacheEnabled"=>false,
   "browserConnectionEnabled"=>false,
   "webStorageEnabled"=>false,
   "acceptSslCerts"=>false,
   "proxy"=>{"proxyType"=>"direct"},
   "phantomjs.page.settings.userAgent"=>
    "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0"}>
Run Code Online (Sandbox Code Playgroud)

除了"phantomjs.page.settings.userAgent"之外,我还尝试了"userAgent"等等.在过去的3-4个小时里我能在网上找到的所有东西,我都试过了.显然,在2013年初,这是一个相当普遍的问题,而我所说的解决方案显然是常见的解决方案.这些都不起作用,事实上,我从这一点信息中确切地知道这一点(注意User-Agent是"Ruby"):

UNCAUGHT EXCEPTION: {"errorMessage"=>"Element is not currently visible and may not be manipulated",
 "request"=>
  {"headers"=>
    {"Accept"=>"application/json",
     "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
     "Connection"=>"close",
     "Content-Length"=>"2",
     "Content-Type"=>"application/x-www-form-urlencoded",
     "Host"=>"localhost:9876",
     "User-Agent"=>"Ruby"},
   "httpVersion"=>"1.1",
   "method"=>"POST",
   "post"=>"{}",
   "postRaw"=>"{}",
   "url"=>"/click",
   "urlParsed"=>
    {"anchor"=>"",
     "query"=>"",
     "file"=>"click",
     "directory"=>"/",
     "path"=>"/click",
     "relative"=>"/click",
     "port"=>"",
     "host"=>"",
     "password"=>"",
     "user"=>"",
     "userInfo"=>"",
     "authority"=>"",
     "protocol"=>"",
     "source"=>"/click",
     "queryKey"=>{},
     "chunks"=>["click"]},
   "urlOriginal"=> …
Run Code Online (Sandbox Code Playgroud)

ruby user-agent phantomjs selenium-webdriver ghostdriver

2
推荐指数
1
解决办法
5652
查看次数

Selenium with PhantomJS:Yahoo登录表单未提交(Python绑定)

我正在OS X上使用selenium webdriver编写一个python 2.7脚本来登录Yahoo fantasy体育并自动执行某些操作.

该脚本适用于webDriver Firefox和Chromedriver.我最近开始使用PhantomJS(GhostDriver),我发现我无法让PhantomJS Selenium Driver(GhostDriver)登录到Yahoo登录表单.

#!/usr/bin/python
import time
from selenium import webdriver
from selenium.webdriver import PhantomJS
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from sys import argv
import click

@click.command()
@click.option('--days', type=int, prompt='Number of days to set active lineup', help='Number of days to set active lineup')
@click.option('--username', prompt='Your Yahoo username:', help='Your Yahoo account username')
@click.option('--password', prompt='Your Yahoo passwordname:', help='Your Yahoo account password')
def start_active_players(days, username, …
Run Code Online (Sandbox Code Playgroud)

python selenium webdriver phantomjs ghostdriver

2
推荐指数
1
解决办法
2900
查看次数

设置PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY

我无法PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY正确设置我的Java程序中的功能,以便从github使用最新版本的Ghostdriver和我安装的phantomjs版本(1.9.1)

这是我在Java程序中所做的

DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(
    PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
    "/xxx/phantomjs-1.9.1-linux-x86_64/bin/phantomjs" );
caps.setCapability(
    PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,
    "/xxx/ghostdriver/src/main.js");
WebDriver driver = new PhantomJSDriver(caps);
Run Code Online (Sandbox Code Playgroud)

selenium驱动程序正确启动,如果我没有设置PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,但我在我的测试中得到一些错误,应该在ghostdriver的当前开发人员分支中修复.所以我遵循了这个建议并设置了ghostdriver的cuttent github版本.

但是,现在我收到以下错误:

[ERROR - 2013-07-12T10:22:36.897Z] GhostDriver - Main - Could not start Ghost Driver => {
  "message": "Could not start Ghost Driver",
  "line": 79,
  "sourceId": 140320571924032,
  "sourceURL": "/xxx/ghostdriver/src/main.js",
  "stack": "Error: Could not start Ghost Driver\n    at /xxx/ghostdriver/src/main.js:79",
  "stackArray": [
    {
      "sourceURL": "/xxx/ghostdriver/src/main.js",
      "line": 79
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,有谁知道如何解决这个问题?我必须config.js以某种方式更改ghostdriver以使其工作吗?

信息:我 …

java phantomjs selenium-webdriver ghostdriver

1
推荐指数
1
解决办法
4513
查看次数