gpt4 book ai didi

node.js - 错误消息: Unable to find element with xpath in phantomsJS

转载 作者:太空宇宙 更新时间:2023-11-04 02:39:14 24 4
gpt4 key购买 nike

我正在使用简单的 NodeJS 脚本来测试 google.com。使用phantomJS浏览器。

var webdriver = require('selenium-webdriver');
var assert = require('assert');

var driver = new webdriver.Builder().
withCapabilities({
browserName : "phantomjs"
}).
usingServer('http://127.0.0.1:4444/wd/hub').build();

//driver.manage().timeouts().implicitlyWait(60000);

driver.get('http://www.google.com');
driver.findElement(webdriver.By.xpath('//*[@id="gbqf"]')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.getTitle().then(function(title) {
assert.equal("webdriver - Google Search", title);
});

driver.quit();

使用运行独立的 selenium 服务器

> java -jar selenium-server-standalone-2.35.0.jar

使用 node 命令并行运行脚本。

我收到以下错误

> timers.js:103
> if (!process.listeners('uncaughtException').length) throw e;
> ^ UnknownError: Error Message => 'Unable to find element with xpath
> '//*[@id="gbqf"]'' caused by Request =>
> {"headers":{"Accept":"application/json,
> image/png","Connection":"Keep-Alive","Content-Length":"45","Content-Type":"application/json;
> charset=utf-8","Host":"localhost:17476"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//*[@id=\\\"gbqf\\\"]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/440b8b90-0fc8-11e3-8024-5bdaea20ab82/element"}
> Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12
> 15:42:01' System info: os.name: 'Linux', os.arch: 'i386', os.version:
> '2.6.18-8.el5', java.version: '1.6.0_16' Driver info: driver.version:

最佳答案

该页面是否有可能尚未完全加载,因为我知道当我访问 google.com 时,它会将我重定向到本地 google.co.uk 网站。

严格出于调试目的,请在 findElement 命令之前休眠 5 秒。如果有效,请替换为 webdriver,等待该对象出现在屏幕上。

但是,我也注意到您正在将 key 发送到“form”元素。这行得通吗?您不想将 key 发送到输入字段吗?

关于node.js - 错误消息: Unable to find element with xpath in phantomsJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com