标签: phantomjs

Webdriverjs - By 未定义

我正在使用 webdriverjs 打开一个网站并通过其 id 选择一个元素。代码是,

var webdriverjs = require('webdriverjs'),
    client      = webdriverjs.remote({desiredCapabilities:{browserName:'phantomjs'}}).init();

client.url('www.google.com', function(err){
  client.findElement(webdriverjs.By.id('lst-ib')).sendKeys('duck duck go\n')
})
Run Code Online (Sandbox Code Playgroud)

它会抛出错误,

webdriverjs.By is undefined
Run Code Online (Sandbox Code Playgroud)

如何By在 中使用函数webdriverjs

javascript phantomjs webdriver-io

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

如何在 PhantomJS 中登录后在会话中打开特定 URL

我正在使用 PhantomJS 登录 facebook。这是我的代码:

var page = require('webpage').create();
phantom.cookiesEnabled = true;
page.open("http://www.facebook.com/login.php", function(status) {

  if (status === "success") {
    page.evaluate(function() {
        document.getElementById("email").value = "email";
        document.getElementById("pass").value = "pass";
        document.getElementById("loginbutton").click();
    });
    window.setTimeout(function() {
       page.render("page.png");
       phantom.exit();
    }, 5000);
  }
});

page.open("https://www.facebook.com/myprofil", function(status) {

    window.setTimeout(function() {
       page.render("profil.png");
       phantom.exit();
    }, 5000);

});
Run Code Online (Sandbox Code Playgroud)

到目前为止,登录过程一切顺利,但我没有找到正确的方法来访问我的个人资料 URL,例如在同一会话中。我尝试再次使用 page.open,但我不断收到带有我请求的页面的登录表单,就好像我以前从未登录过一样。在会话中导航的正确方法是什么?

javascript phantomjs

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

在 Node.js 中更改 JPEG 文件 DPI 标头

我有一个文件(例如 JPEG 大小 1588 × 2244px)。它由puppeteer(但phantomjs也生成72 DPI屏幕截图)生成。当我将此图像保存到带有.jpeg扩展名的文件中并使用 macOS 常规信息时,我看到:

在此处输入图片说明

如您所见,它已72 DPI在元数据中设置,但我想将文件与300 DPI. 我知道,在数字中它不会改变任何东西——它是打印的属性,但我不想向每个客户解释这个文件可以用300 DPI.

当我使用 Gimp 和 Image > Print Size

在此处输入图片说明

我可以更改 DPI,然后再次导出图片。现在它300 DPIGeneral Info窗口中。

在此处输入图片说明

我尝试在 Node.JS 服务器中执行此操作,但我发现很少有选项可以更改.PNG图片上的此属性,但任何人都在处理.JPEG文件。

我认为最准确的选择是使用changeDpiDataUrl这个库中的方法:https : //github.com/shutterstock/changeDPI/blob/master/src/index.js 但是当我把我的图像作为base64imagesplit操作后我有array只有 1 个元素 - 我认为这是正文,所以我没有格式属性(在 63 行)。

有人遇到过这个问题吗?

jpeg node.js phantomjs puppeteer

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

使用phantomjs抓取站点地图

我对phantomjs很新.很长时间以来,我一直在搞乱这些问题.我知道我错过了很简单的事情.我有以下sitemap.xml:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  <url>
    <loc>/</loc>
    <changefreq>always</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>/vehicles</loc>
    <lastmod>2013-01-07</lastmod>
  </url>
</urlset>
Run Code Online (Sandbox Code Playgroud)

现在我要做的就是使用phantomjs从xml文档中获取url值.我有以下内容.

page.open("sitemap.xml", function(status) {
    if(status !== "success") {
        console.log("Unable to open sitemap.");
    } else {
        // Stuck here
        console.log(page.content);
    }
});
Run Code Online (Sandbox Code Playgroud)

xml文件的内容将正确打印到屏幕上,但是如何使用该文档来播放xml?我只需要能够获得每个url节点的第一个子节点.我尝试将xml文档解析为DOMParser,但这似乎不对.非常感谢您的帮助.

另外你如何调试phatomjs所以我可以看到它的全部荣耀的对象?例如,如果我在Dev Tools中控制一个对象,我可以展开它并查看键 - 值对.我猜终端不提供这种奢侈品?

javascript xml xml-parsing phantomjs

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

设置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
查看次数

从grails服务调用phantom.js

我需要从grails服务调用一个phantom.js脚本来创建一个我可以缓存的PNG图像.

我用幻像和grails看到的所有例子都涉及使用幻像进行测试,所以我不确定如何从服务中管理它.

从grails服务调用脚本时最好的做法是什么?

它使用自定义脚本根据传入的URL创建图像.

这将是命令行上的equivelant:

./phantomjs createImage.js http://www.toBeConcerted.com output.png

grails phantomjs

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

当Casperjs在另一个页面上时,它会加载任何URL

我有两个网址X和Y.当casperjs在X页面上时,它必须调用Y页面,在得到响应之后它应该继续.

casper.start("X URL",function() {
   var casper2 = require('casper').create();

   casper2.start();
   casper2.open("Y URL", function() {
        RESPONSE
   });
   casper2.run();

}).then... >> It have to wait for response.
Run Code Online (Sandbox Code Playgroud)

我能怎么做?

phantomjs casperjs

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

CasperJS无法识别PhantomJS网页模块

运行最新版本的Casper 1.1.0-beta3和Phantom 1.9.7.但是,即使是最简单的casper脚本:

var casper = require('casper').create();

casper.start('http://casperjs.org/', function() {
    this.echo('foo');
});

casper.run();
Run Code Online (Sandbox Code Playgroud)

因类型错误而失败

TypeError: 'undefined' is not a function (evaluating 'require('webpage').create()')
  /usr/local/src/casperjs/modules/casper.js:2446 in createPage
  /usr/local/src/casperjs/modules/casper.js:1703 in start
  /var/sites/phantom/simple.js:5
Run Code Online (Sandbox Code Playgroud)

所需的"网页"是PhantomJS模块,在运行幻像脚本时工作正常.require方法似乎也可以正常工作(按照上面的第1行)加载自身,所以看起来PhantomJS只能被选择性识别.

Phantom安装在我的$ PATH上的/ usr/local/bin中.Casper符号链接到同一位置.O/S是Ubuntu 13.10.

关于如何说服Casper与Phantom(或反之亦然)玩得很好的任何建议都将非常感激.

phantomjs casperjs

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

PhantomJSDriver适用于HTTP,但不适用于HTTPS

public class FooTest {
    WebDriver driver;

    @Before
    public void beforeTest() {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setJavascriptEnabled(true);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

        driver = new PhantomJSDriver(capabilities);
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
    }

    @Test
    public void test() {
        driver.get("http://www.example.com");

        WebElement e = driver.findElement(By.tagName("h1"));
        System.out.println("TEXT" + e.getAttribute("innerHTML"));
        assertNotNull(e);
        driver.quit();
    }

}
Run Code Online (Sandbox Code Playgroud)

嗨,我只是想在www.example.com上尝试获取"示例域"的h1标签.该代码适用于http://www.example.com,但不适用于https://www.exmaple.com.我该如何解决这个问题?谢谢

java selenium phantomjs

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

Npm安装的PhantomJS挂断了

每当我尝试通过包含phantomJS的npm安装package.json,或者使用它作为依赖项的软件包时,安装都会挂起在phantomJS安装上.不知道是什么导致这个,任何想法?

>$ npm install
|
> phantomjs@1.9.7-10 install c:\Users\user\application\node_modules\grunt-mo
cha\node_modules\grunt-lib-phantomjs\node_modules\phantomjs
> node install.js
\
Run Code Online (Sandbox Code Playgroud)

它只是无限期地停留在那里(最后一次斜线旋转)

详细输出:

    npm info install sntp@0.2.4 into c:\Users\Nick\extensionTest\node_modules\phan
    tomjs\node_modules\request\node_modules\hawk
    npm info install cryptiles@0.2.2 into c:\Users\Nick\extensionTest\node_modules
    \phantomjs\node_modules\request\node_modules\hawk
    npm info install boom@0.4.2 into c:\Users\Nick\extensionTest\node_modules\phan
    tomjs\node_modules\request\node_modules\hawk
    npm info installOne hoek@0.9.1
    npm info installOne sntp@0.2.4
    npm info installOne cryptiles@0.2.2
    npm info installOne boom@0.4.2
    npm info c:\Users\Nick\extensionTest\node_modules\phantomjs\node_modules\reque
    st\node_modules\hawk\node_modules\hoek unbuild
    npm info c:\Users\Nick\extensionTest\node_modules\phantomjs\node_modules\reque
    st\node_modules\hawk\node_modules\sntp unbuild
    npm info c:\Users\Nick\extensionTest\node_modules\phantomjs\node_modules\reque
    st\node_modules\hawk\node_modules\cryptiles unbuild
    npm info c:\Users\Nick\extensionTest\node_modules\phantomjs\node_modules\reque
    st\node_modules\hawk\node_modules\boom unbuild
    npm verb tar unpack C:\Users\Nick\AppData\Roaming\npm-cache\hoek\0.9.1\packa
    ge.tgz
    npm …
Run Code Online (Sandbox Code Playgroud)

package node.js npm phantomjs

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