使用Javascript中的Webdriver返回DOM元素
如何使用Javascript中的Webdriver返回DOM元素 我正在使用wd.js Javascript绑定:使用Javascript中的Webdriver返回DOM元素,javascript,dom,selenium-webdriver,Javascript,Dom,Selenium Webdriver,如何使用Javascript中的Webdriver返回DOM元素 我正在使用wd.js Javascript绑定: require("wd") .remote("promiseChain") .init() .get("http://www.google.com") .elementById("mngb") .then(function(element) { console.log(element); }); 我得到的这个奇怪的对象不是标准的DOM元素,例如,我无法从中提取
require("wd")
.remote("promiseChain")
.init()
.get("http://www.google.com")
.elementById("mngb")
.then(function(element) { console.log(element); });
我得到的这个奇怪的对象不是标准的DOM元素,例如,我无法从中提取HTML代码:
{ value: '0',
browser:
{ domain: null,
_events: {},
_maxListeners: 10,
configUrl:
{ protocol: 'http:',
slashes: true,
auth: null,
host: '127.0.0.1:4444',
port: '4444',
hostname: '127.0.0.1',
hash: null,
search: '',
query: {},
pathname: '/wd/hub',
path: '/wd/hub',
href: 'http://127.0.0.1:4444/wd/hub' },
sauceRestRoot: 'https://saucelabs.com/rest/v1',
noAuthConfigUrl:
{ protocol: 'http:',
slashes: true,
host: '127.0.0.1:4444',
port: '4444',
hostname: '127.0.0.1',
hash: null,
search: null,
query: null,
pathname: '/wd/hub',
path: '/wd/hub',
href: 'http://127.0.0.1:4444/wd/hub' },
defaultCapabilities:
{ browserName: 'firefox',
version: '',
javascriptEnabled: true,
platform: 'ANY' },
_httpConfig:
{ timeout: undefined,
retries: 3,
retryDelay: 15,
baseUrl: undefined },
sampleElement: { value: 1, browser: [Circular] },
sessionID: '238c9837-3d82-4d90-9594-cefb4ba8e6b9' } }
使用任何Webdriver客户机都不可能获得实际的Javascript DOM元素,但是在大多数情况下应该没有问题,因为getAttribute方法是可用的。 例如:
require("wd")
.remote("promiseChain")
.init()
.get("http://www.google.com")
.elementById("mngb")
.getAttribute("outerHTML")
.then(console.log.bind(console))
返回www.google.com上mngb的HTML代码
如果确实需要使用DOM元素,可以使用