2015-10-14 23 views
2

HTML代碼不能發送鍵字段鉻(在Firefox相同的代碼工作)

<textarea type="text" name="pos_description" rows="4" class="form-control ng-pristine ng-invalid ng-invalid-required ng-valid-minlength ng-valid-maxlength ng-touched" id="pos_description" placeholder="Enter Description" ng-model="data.description" minlength="150" maxlength="5000" required=""> 
    </textarea> 

我的代碼

browser.executeScript('window.scrollTo(0,250);'); 
browser.sleep(3000); 
element(by.model('textarea.data.description')).sendKeys("values"); 

我收到如下錯誤: -

StaleElementReferenceError: stale element reference: element is not attached to the page do

cument

(Session info: chrome=43.0.2357.132) (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.13.0-55-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 45 milliseconds

請幫我

+0

你可以更新你的瀏覽器到最新版本,並檢查你是否仍然得到這個錯誤?你還在用什麼版本的量角器和硒webdriver? –

回答

1

這可能是mo狡猾,因爲頁面沒有正確加載。頁面可能已經加載,但頁面中的某些元素可能會加載,從頁面中消失幾秒鐘,然後再次加載。所以當頁面加載時,Selenium發現文本區域,當它嘗試點擊時,元素可能已經重新加載。

在量角器中放上一個等同的嘗試catch,以捕獲異常並再次找到該元素,然後單擊第二次。

try { 
    element(by.model('textarea.data.description')).sendKeys("values"); 
} catch (StaleElementReferenceError e) { 
    element(by.model('textarea.data.description')).sendKeys("values"); 
} 

我不知道這是可能的量角器。如果不是,你總是可以增加睡眠時間。

0

你的HTML看起來像這樣:NG-模型= 「data.description」 但你這樣做是:元素(by.model( 'textarea.data.description'))

它應該是:元素(by.model('data.description'))

+0

我試過這個,但它不工作。請建議 –

相關問題