请考虑以下代码段
var allRows = element.all(by.repeater('row in items'))
这将返回array
个转发器项。那么,我如何在控制台中调试此变量。当我执行console.log(allRows)
时,我在控制台中得到以下内容而不是html
的数组。
{ ptor_: { controlFlow: [Function],
schedule: [Function],
setFileDetector: [Function],
getSession: [Function],
getCapabilities: [Function],
quit: [Function],
actions: [Function],
touchActions: [Function],
executeScript: [Function],
executeAsyncScript: [Function],
call: [Function],
wait: [Function],
sleep: [Function],
getWindowHandle: [Function],
getAllWindowHandles: [Function],
getPageSource: [Function],
close: [Function],
getCurrentUrl: [Function],
getTitle: [Function],
findElementInternal_: [Function],
findElementsInternal_: [Function],
takeScreenshot: [Function],
manage: [Function],
switchTo: [Function],
driver:
WebDriver {
session_: [Object],
executor_: [Object],
flow_: [Object],
fileDetector_: null },
element: { [Function] all: [Function] },
'$': [Function],
'$$': [Function],
baseUrl: '',
rootEl: 'html',
ignoreSynchronization: false,
getPageTimeout: 100000,
params: {},
ready:
Promise {
flow_: [Object],
stack_: null,
parent_: null,
callbacks_: null,
state_: 'fulfilled',
handled_: true,
value_: null,
queue_: null },
plugins_:
{ pluginConfs: [],
pluginObjs: [],
assertions: {},
resultsReported: false },
resetUrl: 'data:text/html,<html></html>',
trackOutstandingTimeouts_: true,
mockModules_: [ [Object] ],
allScriptsTimeout: 100000,
getProcessedConfig: [Function],
forkNewDriverInstance: [Function],
restart: [Function] },
那么如何调试应包含所有html行的实际变量。我在调试docs中找不到它的选项。
非常感谢任何帮助。
感谢。
更新
allRows
有以下标记。
<li>AA</li><li>BB</li><li>CC</li>
我需要在控制台中查看整个内容
答案 0 :(得分:2)
请记住,几乎每个Protractor函数都会返回一个必须在继续之前解决的promise。如果您想查看变量allRows
allRows.each(function(row)getInnerHtml().then(function(html) {
console.log(html);
});
Promise可以在expect方法中解析,因此假设变量myHtmlString
引用了预期结果,您可以将上述内容缩短为:
expect(allRows.getInnerHtml()).toBe(myHtmlString);
对更新的回应:
你想要的是父元素的innerHtml。您可以使用xpath函数获取它,但它们是最慢的选择方法,因此,应该仅用作最后的手段。如果你可以直接获得/,那么我提供的代码将起作用。如果由于某种原因,您无法直接获取列表元素,那么
var firstItem = allRows.first();
var parent = firstItem.element(by.xpath('..'));
parent.getInnerHtml().then(function(html) {
console.log(html);
});
应在控制台中打印所需的结果。
答案 1 :(得分:2)
我认为您正在寻找getOuterHtml()
- 它将打印出指定元素的整个元素标记(包括html属性)。例如,
it('prints element', function () {
var el = element(by.model('username'));
el.getOuterHtml().then(function (val) {
console.log(val);
});
});
这会产生:
来源:https://angular.github.io/protractor/#/api?view=webdriver.WebElement.prototype.getOuterHtml