在Selenium中发出POST请求而不填写表单

使用selenium,您可以执行任意Javascript,包括以程式提交表单.

使用Selenium Java最简单的JS执行:

if (driver instanceof JavascriptExecutor) {
    ((JavascriptExecutor) driver).executeScript("alert('hello world');");
}

并使用Javascript,您可以创建发布请求,设置所需的参数和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');

|

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容