在尝试声明在以下网页中输入的日期getAttribute('value')时,返回“ Object(浏览器,然后是...)”,而不是value。 https://material.angular.io/components/datepicker/examples
以下是给出错误的代码段
expect(element(by.xpath('//input[@id="mat-input-2"]')).getAttribute('value')).to.eventually.equal(element(by.xpath('//input[@id="mat-input-2"]')).getAttribute('value')).and.notify(callback);
为此,我遇到以下错误 AssertionError:预期'1/6/2019'等于{Object(browser_,then,...)}
var date=element(by.xpath('//input[@id="mat-input-2"]')).getAttribute('value').getText();
console.log(date);
上面代码的console.log返回的是这样的东西。
ElementFinder {
browser_:
ProtractorBrowser {
controlFlow: [Function],
schedule: [Function],
setFileDetector: [Function],
getExecutor: [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:
Driver {
flow_: [ControlFlow],
session_: [ManagedPromise],
executor_: [Executor],
fileDetector_: null,
onQuit_: undefined,
getNetworkConnection: [Function],
setNetworkConnection: [Function],
toggleAirplaneMode: [Function],
toggleWiFi: [Function],
请为此提供一些解决方案
答案 0 :(得分:0)
尝试:
const elementOne = element(by.xpath('//input[@id="mat-input-2"]');
const elementTwo = element(by.xpath('//input[@id="mat-input-2"]');
return elementOne.getAttribute('value').then((elementOneValue) => {
return expect(elementTwo.getAttribute('value')).to.eventually.equal(elementOneValue).and.notify(callback);
});
顺便说一句。这两个元素都有相同的选择器-必须相等。