2017-04-19 85 views
1

我查看了this question與CSS選擇器的問題。接受的答案是完全離開nightwatch.js。我希望這種情況不是這樣,但有問題。Nightwatch.js通過CSS選擇器查找的問題(最新版本)

我已經升級到最新的可用nightwatch.js v0.9.14,但無法通過jQuery找到它在屏幕上找到的元素。

使用下面的選擇器(必要的層次結構,因爲它是一個jqGrid的範圍內):

.click("#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select") 

我得到:

ERROR: Unable to locate element: "#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select 
using: css selector 

也試圖從this question(選擇方法不希望這樣做,因爲ID是動態的):

.click('select[id="null_z01rsnload_inst_ref"]') 

不符合:

ERROR: Unable to locate element: "select[id="null_z01rsnload_inst_ref"]" using: css selector 

在控制檯中使用jQuery:

$("#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select") 

返回:

[select#null_z01rsnload_inst_ref.editable, prevObject: init(1), context: document, selector: "#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(4) > select"] 

我之前(尤其是與選擇的和他們的選項)but the method mentioned in the answer by 79E09796 has worked for me previously也有類似的問題這一點。

這是使用chromedriver.exe版本2.28在Chrome(我們的主要目標,我們目前沒有爲其他平臺進行自動測試)。它不在iframe內。

添加「--verbose」對夜巡命令行給我:

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>.. 

任何進一步的想法,將不勝感激!

+0

你可以試試用--verbose運行Nightwatch嗎?如果它做錯了什麼,你可能會看到它將POST中的選擇器字符串改爲Selenium。否則,它只是打印返回的錯誤(您也將在詳細輸出中看到)。也許.waitForElementPresent()第一次? –

+0

一些注意事項:在某些情況下,您應該可以使用querySelector。另外,什麼瀏覽器有這個問題,還是所有的瀏覽器?另外,嵌套在iframe中的元素是什麼?在你操縱它的HTML元素之前,你需要明確地選擇iframe。 – QualiT

+0

增加了chromedriver信息,此刻進行更多調試。 – u02sgb

回答

0

由於@BoltClock表示eq()運算符不是有效的CSS選擇器,它是jQuery特有的。我改爲使用nth-child()代替。

所以:

.assert.elementPresent("#MedicalHistoryAmendment_sheet tbody tr:eq(1) > td:eq(7) select") 

需要是:

.assert.elementPresent("#MedicalHistoryAmendment_sheet tbody tr:nth-child(2) > td:nth-child(8) select") 

要更改,需要通過1增加指標,並牢記它可以抓住額外的元素depending on the structure。這一類是jQuery的

其他選擇只能是gt()lt()

感謝所有幫助大家。