使用selenium,您可以執(zhí)行任意Javascript,包括以程式提交表單.
使用Selenium Java最簡單的JS執(zhí)行:
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("alert('hello world');");
}
并使用Javascript,您可以創(chuàng)建發(fā)布請求,設置所需的參數(shù)和HTTP標頭并提交.
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://domain.com', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
alert(this.responseText);
};
xhr.send('login=test&password=test');
|