First approach
You can provide credentials in URL itself it means we will add username and password in URL so while running script it will bypass the same.
Syntax
http://username:password@url
Example :
http://mukeshotwani:password1234@www.xyz.com
If username/password contanis the following special characters, you should use URL encoding(Percent-encoding)
] [ ? / < ~ # ` ! @ $ % ^ & * ( ) + = } | : " ; ' , > { space
Example(username "user@example.com" and password "pass!word"):
http://user%40example.com:pass%21word@www.xyz.com
Example(Java):
String url = "http://" + URLEncoder.encode("user@example.com", "UTF-8") + ":" + URLEncoder.encode("pass!word", "UTF-8") + "@www.xyz.com";
Second approach
使用AutoAuth Firefox插件。需要先保存网站密码(密码保存在Firefox 的profile配置文件中),AutoAuth会自动提交验证对话框。Selenium firefox driver 中默认的配置signon.rememberSignons为false,这个值不能在代码中更改,因此不能通过完全使用编码的方式构建FirefoxProfile,需要先安装好AutoAuth,保存好密码,再以此profil