login_script error using xpath with watir api

Thierry Beauquier's Avatar

Thierry Beauquier

29 Mar, 2017 02:16 PM


Got the following error [ArgumentError] expected Hash or (:how, 'what'), got ["username1"] when using login script with watir xpath API. When using text_field API, watir was not able to locate any element provided

(unable to locate element, using {:name=>"username", :tag_name=>"input or textarea", :type=>"(any text type)

Login script :

browser.goto ""
browser.element(:xpath => "//input[@class='ebInput.eaLogin-loginUsername']").set("username1")
browser.element(:xpath => "//input[@class='ebInput.eaLogin-loginPassword']").set("password1")
browser.element(:xpath => "//button[@class='ebBtn.eaLogin-formButton.eaLogin-form-submit']").click

I am using latest arachni version (1.5.1-0.5.12). Attached the complete arachni log and html form


  1. Support Staff 1 Posted by Tasos Laskos on 29 Mar, 2017 03:06 PM

    Tasos Laskos's Avatar

    I don't think you are using XPath properly, try removing ebInput. and ebBtn.eaLogin-formButton. from the expressions.

  2. 2 Posted by Thierry Beauqui... on 29 Mar, 2017 04:17 PM

    Thierry Beauquier's Avatar

    No, I got the same error.

  3. Support Staff 3 Posted by Tasos Laskos on 29 Mar, 2017 05:14 PM

    Tasos Laskos's Avatar

    Can you please place the following after the goto call and show me the output?

    puts browser.source
  4. 4 Posted by Thierry Beauqui... on 29 Mar, 2017 08:28 PM

    Thierry Beauquier's Avatar

    Sorry but not much useful information

    `[~] No checks were specified, loading all. [~] No element audit options were specified, will audit links, forms, cookies, UI inputs, UI forms, JSONs and XMLs.

    [] Initializing... [] Preparing plugins... [~] Login script: Running the script. #Watir::Source:0x00000005599278 [-] [utilities#exception_jail:428] Session: [ArgumentError] expected Hash or (:how, 'what'), got ["user"] [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/components/plugins/login_script.rb:29:in eval' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/svg_elements.rb:699:inset' [-] [utilities#exception_jail:428] Session: (eval):17:in block in prepare' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/components/plugins/login_script.rb:29:ineval' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/components/plugins/login_script.rb:29:in block in prepare' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/components/plugins/login_script.rb:47:incall' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/components/plugins/login_script.rb:47:in block in prepare' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/lib/arachni/session.rb:322:incall' [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/ar `

  5. 5 Posted by Thierry Beauqui... on 29 Mar, 2017 09:42 PM

    Thierry Beauquier's Avatar

    I got the printout by using "puts browser.html" instead and noticed that the element I need to access is contained inside

    and it is not displayed by watir but can be seen when using Inspector from FF. So watir does not load the js container dynamically but only the pure html source ?

    I sent you the js code inside

    in login.html and see attachment for arachni output


  6. Support Staff 6 Posted by Tasos Laskos on 30 Mar, 2017 08:13 AM

    Tasos Laskos's Avatar

    I'm assuming the container is populated by an AJAX call, in that case you will have to wait for the form elements to appear, see: http://www.rubydoc.info/gems/watir-webdriver/Watir%2FEventuallyPres...

    If that doesn't work either then I'll need access to the webapp in order to debug it.

  7. 7 Posted by Thierry Beauqui... on 30 Mar, 2017 12:37 PM

    Thierry Beauquier's Avatar

    It timed out when looking for "username" text_field. If you have any other idea, let me know anyway I will ask design to confirm for the AJAX call and try to get help from them.

    Unfortunately it is not possible to access the webapp from internet.

    There is REST api also to access the webapp so my next step would be to scan it with arachni.


  8. 8 Posted by Thierry Beauqui... on 30 Mar, 2017 04:19 PM

    Thierry Beauquier's Avatar

    Talked to design and there is no AJAX involved just javascript. They are using also Selenium/webdriver with Java and they do as you suggest, waiting for the container to load before login.

  9. 9 Posted by Thierry Beauqui... on 30 Mar, 2017 04:46 PM

    Thierry Beauquier's Avatar

    I have been able to get the container loaded in watir and being seen by arachni using the following in the login script

    browser.div(:id => "container").wait_until_present
    puts browser.html
    form = browser.form( name: 'loginForm')
    form.text_field( name:  'username').set 'user1'
    form.text_field( name: 'password').set 'password1'

    However I got a another error from Selenium:

     [-] [utilities#exception_jail:428] Session: [Selenium::WebDriver::Error::InvalidElementStateError] {"errorMessage":"Element is not currently interactable and may not be manipulated","request":{"headers":{"Accept":"application/json","Accept-Encoding":"gzip;q=1.0,deflate;q=0.6,identity;q=0.3","Connection":"close","Content-Length":"2","Content-Type":"application/x-www-form-urlencoded","Host":"","User-Agent":"Ruby"},"httpVersion":"1.1","method":"POST","post":"{}","postRaw":"{}","url":"/clear","urlParsed":{"anchor":"","query":"","file":"clear","directory":"/","path":"/clear","relative":"/clear","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/clear","queryKey":{},"chunks":["clear"]},"urlOriginal":"/session/c8201510-1567-11e7-b8f7-4710787239ef/element/:wdc:1490892114802/clear"}} (org.openqa.selenium.InvalidElementStateException)
     [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/arachni-1.5.1/components/plugins/login_script.rb:29:in eval&#39;
     [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/response.rb:32:ininitialize'
     [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:81:in new&#39;
     [-] [utilities#exception_jail:428] Session: /home/lmcthbe/Downloads/arachni-1.5.1-0.5.12/system/gems/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:81:increate_response'
  10. 10 Posted by Thierry Beauqui... on 31 Mar, 2017 03:19 PM

    Thierry Beauquier's Avatar

    I think that I found the issue, the element (username, password) where already filled because of auto-complete (can be seen from FF) so just doing form.submit did the trick.

    Discussion can be closed.


  11. Tasos Laskos closed this discussion on 01 Apr, 2017 10:46 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac