I looked into this question for issues with CSS selectors. The accepted answer is move away from nightwatch.js altogether. I'm hoping this isn't still the case but am having problems.
I've upgraded to the latest available nightwatch.js v0.9.14 but can't get it to find elements on screen that I can find using jQuery.
Using the selector below (hierarchy necessary as it's within a jqGrid):
.click("#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select")
I get:
ERROR: Unable to locate element: "#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select
using: css selector
Also trying the selector method from this question (would prefer not to do this as the ids are dynamic):
.click('select[id="null_z01rsnload_inst_ref"]')
Fails with:
ERROR: Unable to locate element: "select[id="null_z01rsnload_inst_ref"]" using: css selector
Using jQuery in the console:
$("#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select")
Returns:
[select#null_z01rsnload_inst_ref.editable, prevObject: init(1), context: document, selector: "#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select"]
I've had similar issues to this before (particularly with select's and their options) but the method mentioned in the answer by 79E09796 has worked for me previously.
This is on Chrome (our primary target, we're not doing automated testing for other platforms at the moment) using chromedriver.exe version 2.28. It is not inside an iframe.
Adding "--verbose" to the nightwatch command line gave me:
INFO Request: POST /wd/hub/session/50a51b48-bce9-425d-a132-2d0407c8ac21/elements
- data: {"using":"css selector","value":"#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(7) select"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":98}
ERROR Response 500 POST /wd/hub/session/50a51b48-bce9-425d-a132-2d0407c8ac21/elements (1019ms) { sessionId: '50a51b48-bce9-425d-a132-2d0407c8ac21',
status: 32,
value:
{ message: 'invalid selector: An invalid or illegal selector was specified\n
..<snip>..
Any further ideas would be much appreciated!