我在以下部分嵌入了以下命令:
verify: function (input) {
this
.waitForElementVisible('@value');
this
.getValue('.keystone-body form .field-type-text[for="name"] input[name="name"]', function(result) {
this.assert.equal(result.value, input.value);
});
this
.getValue('.keystone-body form .field-type-text[for="name"]', function(result) {
console.log('***result: ' + JSON.stringify(result));
});
this
.getValue('@value', function (result) {
console.log('***result: ' + JSON.stringify(result));
});
return this;
},
正如您在Selenium日志中看到的,所有四个函数调用都引用相同的选择器树(第三个实际上是选择器树的表示,导致异常发生在第四个上)。前三个工作就好了。但是,第四个不会在下面的日志中生成异常。请注意,在第三个中,我使用了相同的选择器导致异常并且工作正常。我已经转到发生这种情况的页面使用了以下查询(与上面的第3和第4个查询相同)并且工作正常:
document.querySelector('.keystone-body form .field-type-text[for="name"]')
守夜人日志:
✔ Element <Section[name=form],Section[name=nameList],Section[name=nameField],Element[name=@value]> was visible after 64 milliseconds.
✔ Passed [equal]: Name Field Test 1 == Name Field Test 1
***result: {"state":"success","sessionId":"72e0085f-086a-443e-b71f-e893fcbd4fdc","hCode":484670138,"value":null,"class":"org.openqa.selenium.remote.Response","status":0}
***result: {"status":-1,"value":{"additionalInformation":"\nDriver info: driver.version: unknown","localizedMessage":"Unable to locate element: {\"method\":\"css selector\",\"selector\":\".field-type-text[for=\\\"name\\\"]\"}\nFor documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html\nBuild info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'\nSystem info: host: 'XPS8500', ip: '10.0.0.208', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_31'\nDriver info: driver.version: unknown","supportUrl":"http://seleniumhq.org/exceptions/no_such_element.html","systemInformation":"System info: host: 'XPS8500', ip: '10.0.0.208', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_31'","cause":null,"suppressed":[],"message":"Unable to locate element: {\"method\":\"css selector\",\"selector\":\".field-type-text[for=\\\"name\\\"]\"}\nFor documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html\nBuild info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'\nSystem info: host: 'XPS8500', ip: '10.0.0.208', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_31'\nDriver info: driver.version: unknown","hCode":2047706588,"class":"org.openqa.selenium.NoSuchElementException","buildInformation":{"buildRevision":"4c2593c","buildTime":"2016-02-11 19:06:42","releaseLabel":"2.52.0","hCode":825790507,"class":"org.openqa.selenium.internal.BuildInfo"}},"errorStatus":7,"error":"An element could not be located on the page using the given search parameters."}
ERROR: Unable to locate element: "Section[name=form],Section[name=nameList],Section[name=nameField],Element[name=@value]" using: recursion
at Section.getValue (C:\Users\Joe\git\prs\node_modules\nightwatch\lib\page-object\command-wrapper.js:103:25)
at Section.NameList.sections.nameField.commands.verify (C:\Users\Joe\git\prs\test\e2e\adminUI\pages\lists\name.js:35:9)
at Object.module.exports.Name field can be created via the initial modal (C:\Users\Joe\git\prs\test\e2e\adminUI\tests\group005Fields\uxTestNameField.js:51:5)
at Module.call (C:\Users\Joe\git\prs\node_modules\nightwatch\lib\runner\module.js:63:34)
at C:\Users\Joe\git\prs\node_modules\nightwatch\lib\runner\testcase.js:97:29
at _fulfilled (C:\Users\Joe\git\prs\node_modules\nightwatch\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\Joe\git\prs\node_modules\nightwatch\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\Joe\git\prs\node_modules\nightwatch\node_modules\q\q.js:796:13)
at C:\Users\Joe\git\prs\node_modules\nightwatch\node_modules\q\q.js:556:49
at runSingle (C:\Users\Joe\git\prs\node_modules\nightwatch\node_modules\q\q.js:137:13)
at flush (C:\Users\Joe\git\prs\node_modules\nightwatch\node_modules\q\q.js:125:13)
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
ERROR: Unable to locate element: "Section[name=form],Section[name=nameList],Section[name=nameField],Element[name=@value]" using: recursion
Selenium Logs:
18:19:44.893 INFO - Executing: [find elements: By.cssSelector: .keystone-body])^M
18:19:44.901 INFO - Done: [find elements: By.cssSelector: .keystone-body]^M
18:19:44.905 INFO - Executing: [find child elements: 20 [[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body], By.cssSelector: form])^M
18:19:44.911 INFO - Done: [find child elements: 20 [[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body], By.cssSelector: form]^M
18:19:44.915 INFO - Executing: [find child elements: 22 [[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form], By.cssSelector: .field-type-text[for="name"]])^M
18:19:44.915 INFO - Executing: [find child elements: 21 [[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form], By.cssSelector: .field-type-text[for="name"]])^M
18:19:44.924 INFO - Done: [find child elements: 22 [[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form], By.cssSelector: .field-type-text[for="name"]]^M
18:19:44.932 INFO - Done: [find child elements: 21 [[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form], By.cssSelector: .field-type-text[for="name"]]^M
18:19:44.934 INFO - Executing: [find child elements: 23 [[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]], By.cssSelector: input[name="name"]])^M
18:19:44.940 INFO - Done: [find child elements: 23 [[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]], By.cssSelector: input[name="name"]]^M
18:19:44.943 INFO - Executing: [is displayed: 24 [[[[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]]] -> css selector: input[name="name"]]])^M
18:19:44.954 INFO - Done: [is displayed: 24 [[[[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]]] -> css selector: input[name="name"]]]^M
18:19:44.956 INFO - Executing: [find element: By.cssSelector: .keystone-body form .field-type-text[for="name"] input[name="name"]])^M
18:19:44.962 INFO - Done: [find element: By.cssSelector: .keystone-body form .field-type-text[for="name"] input[name="name"]]^M
18:19:44.964 INFO - Executing: [get element attribute: 24 [[[[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]]] -> css selector: input[name="name"]], value])^M
18:19:44.970 INFO - Done: [get element attribute: 24 [[[[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]]] -> css selector: input[name="name"]], value]^M
18:19:44.973 INFO - Executing: [find element: By.cssSelector: .keystone-body form .field-type-text[for="name"]])^M
18:19:44.978 INFO - Done: [find element: By.cssSelector: .keystone-body form .field-type-text[for="name"]]^M
18:19:44.980 INFO - Executing: [get element attribute: 23 [[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]], value])^M
18:19:44.987 INFO - Done: [get element attribute: 23 [[[[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form]] -> css selector: .field-type-text[for="name"]], value]^M
18:19:44.991 INFO - Executing: [find element: By.cssSelector: .keystone-body])^M
18:19:44.997 INFO - Done: [find element: By.cssSelector: .keystone-body]^M
18:19:45.000 INFO - Executing: [find child element: 20 [[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body], By.cssSelector: form])^M
18:19:45.007 INFO - Done: [find child element: 20 [[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body], By.cssSelector: form]^M
18:19:45.012 INFO - Executing: [find child element: 21 [[[[FirefoxDriver: firefox on WINDOWS (237d3a34-9cc3-484e-8d5a-8a01ceb65c41)] -> css selector: .keystone-body]] -> css selector: form], By.cssSelector: .field-type-text[for="name"]])^M
18:19:45.253 WARN - Exception thrown^M
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":".field-type-text[for=\"name\"]"}
我已经完成了这一次,似乎无法找到根本原因。任何指针都将非常感谢!
答案 0 :(得分:0)
事实证明,该页面有一个非常嵌入的小形式,不知何故抛弃了生成的节选择器。