How to do basic authentication using Selenium Webdriver and PhantomJS? -


i'm having trouble authenticating using selenium server 2.33.0, selenium webdriver js binding 2.34.0 (npm package "selenium-webdriver") , phantomjs 1.9.1 on mac 10.6.8. i've tried other js bindings "webdriverjs" , "wd" similar results don't think it's problem binding.

i setup webdriver using this:

return new webdriver.builder().     usingserver('http://localhost:4444/wd/hub').     withcapabilities({         "browsername": "phantomjs",         "phantomjs.page.settings.username":user,         "phantomjs.page.settings.password":password     }).build(); 

i see in selenium server log output:

phantomjs launching ghostdriver... [info  - 2013-08-13t21:52:40.240z] ghostdriver - main - running on port 28904 [info  - 2013-08-13t21:52:40.394z] session [acd0ad70-0462-11e3-95df-4b230b17334d] - constructor - desired capabilities:{"phantomjs.page.settings.password":"xxx","browsername":"phantomjs","phantomjs.page.settings.username":"xxx"} [info  - 2013-08-13t21:52:40.394z] session [acd0ad70-0462-11e3-95df-4b230b17334d] - constructor - negotiated capabilities: {"browsername":"phantomjs","version":"1.9.1","drivername":"ghostdriver","driverversion":"1.0.3","platform":"mac-10.6 (snow leopard)-32bit","javascriptenabled":true,"takesscreenshot":true,"handlesalerts":false,"databaseenabled":false,"locationcontextenabled":false,"applicationcacheenabled":false,"browserconnectionenabled":false,"cssselectorsenabled":true,"webstorageenabled":false,"rotatable":false,"acceptsslcerts":false,"nativeevents":true,"proxy":{"proxytype":"direct"},"phantomjs.page.settings.password":"xxx","phantomjs.page.settings.username":"xxx"} 

i can see negotiated capabilities contain user , password specified. authentication fails when try open page in website uses http basic authentication:

14:43:25.504 info - executing: [find element: by.id: auth-username-field-inputel] @ url: /session/04627dc2-a16c-42b3-b3dc-48e502f7cfec/element) 14:43:29.410 warn - exception thrown org.openqa.selenium.nosuchelementexception: error message => 'unable find element id 'auth-username-field-inputel'' 

if run script against localhost website doesn't have authentication, works fine. if view remote website using firefox (not via selenium), can authenticate , see homepage.

i've tried running phantomjs in webdriver mode using "-w" , i'm getting similar result.

it works if run script phantomjs:

var page=require('webpage').create(); //page.customheaders={'authorization': 'basic '+btoa('xxx:xxx')}; page.settings.username="xxx"; page.settings.password="xxx"; var callback=function(status){     if(timer)window.cleartimeout(timer);     if (status=='success' || status=='timedout') {         console.log(status);         console.log(page.plaintext);     }else{         console.log('failed load.');     }     phantom.exit();     }; var timer=window.settimeout(callback,60000,'timedout'); var url="http://xxx.com"; page.open(url,callback); 

i copied script posting. found 1.9.1 username , password work fine, didn't need set customheader. tried customheader in selenium script didn't make difference. issue ghostdriver.

has been able working?

i in exact same situation.

my theory we're making request using ntlm (windows authentication), solicit 401 (unauthorized) , require resending request username/password combination. ghostdriver quite clear settings apply only during initial call, obviate credentials passed in.

it pretty frustrating javascript version works c# version fails spectacularly.

if there suggestions, love hear them.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -