[英]Selenium - How to use JavascriptExecutor in a JS test file?
我正在嘗試編寫Javascript測試腳本。 我不確定如何在Javascript文件中引用和使用JavascriptExecutor。 如何在Javascript中引用/實例化它? 我正在使用FF。 任何示例代碼將不勝感激。 謝謝
只需將JavaScript代碼插入測試中, 就不需要JavaScriptExecutor了 。
實際上,由於Java是服務器端語言,並且不直接與瀏覽器打交道,因此Java環境中的WebDriver實際上使用JavaScriptExecutor在瀏覽器中運行JavaScript。 這是使用executeScript和executeAsyncScript方法完成的。
使用IJavaScriptExecutor在C#中實現相同的功能 。
編輯:
要滾動到ID,您可以在測試中直接使用以下代碼之一:
window.scroll(horizontalOffset, verticalOffset);
window.location.hash = '#ID';
document.getElementById('ID').scrollIntoView(true);
var divPosition = $('#divId').offset();
$('html, body').animate({scrollTop: divPosition.top}, "slow");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.