2017-04-11 220 views
0

我想我有一些不好的編碼,我正在嘗試寫一個硒測試。有問題的文本框的默認值是「30」,它始終是設置的(服務器端asp.net)。然而,屏幕的執行期間的JavaScript填充文本像這樣:硒文本框NULL文本

document.getElementById("txtEQ").value = eqVal; 

以下是文本框的calulation(JavaScript的)之後的輸出已運行:

enter image description here

然而中,源仍然顯示的值= 「30」

TextBox source

以我硒代碼我試圖獲取文本,但它總是返回null。

Driver.Instance.FindElement(By.Id(txtEQ)).Text 

當我嘗試獲取的價值,我總是得到30

Driver.Instance.FindElement(By.Id(txtEQ)).GetAttribute("Value") 

我也試過這(和許多其他變化):

IJavaScriptExecutor js = (IJavaScriptExecutor)Driver.Instance; 
js.ExecuteScript("document.getElementsByClassName('txtEQ').text;").ToString(); 

返回null每時每刻。

我不確定我可以在這裏做什麼。

回答

0

請嘗試運行此命令:

IJavaScriptExecutor js = (IJavaScriptExecutor)Driver.Instance; 
js.ExecuteScript("$(\"#txtEQ\").val(\"25\").change();") 

觸發元素上的改變事件可能解決這個問題你。

然後做:

Driver.Instance.FindElement(By.Id("txtEQ")).GetAttribute("Value") 
+0

不幸的是,沒有工作。價值保持在30。 – webdad3