Jump to content
Sign in to follow this  
mario52

FF.au3 Form with Jquery disabled Button

Recommended Posts

Hello,

I desparetly need to fill a form (field) with a jquery button disabled(submit). The button get activated only if I fill it with my keyboard (real keypress). I tried many things to get it work but I am now desperate to know if a solution really exist.

The field I am talking about is on my personal mail account but I found a really similar for testing purpose.

#include <_FF.au3>
#include <File.au3>
#include <Array.au3>


$url = "http://www.revillweb.com/demos/jQueryDisableButton/jqueryDisableButton.html"

RunWait("C:\Program Files\FirefoxPortable\FirefoxPortable.exe")
Sleep(1000)

_FFConnect("127.0.0.1", 4242)
Sleep(2000)

;_FFOpenURL($url)
 _FFLoadWait()
 Sleep(1000)

;Fill the field but does not activate the button near
$input = _FFXPath('//*[@id="searchInput"]')
 _FFSetValue('test', $input, 'elements')
$pos = _FFGetPosition($input)

;None of them work
;~ _FFDispatchEvent($input, 'blur')
;~ _FFDispatchEvent($input, 'select')
;~ _FFDispatchEvent($input, 'focus')
;~ _FFDispatchEvent($input, 'click')
;~ _FFDispatchEvent($input, 'mousedown')
;~ _FFDispatchEvent($input, 'keydown', 13)

;~ _FFFormSubmit('submit', 'name')
;~ _FFCmd($input & ".selected")
;~ _FFSetValue('123', $input, 'elements')
;~ _FFDispatchKeyEvent($input, 13, 'keypress') ; pressing "enter" on the input-field

;I could do something crappy like that but, thing is that I got weird control coordinates that needs to be reajusted....
Opt("WinTitleMatchMode", 2)
$win = "Mozilla Firefox"
WinActivate($win, "")
Opt("MouseCoordMode", 2)
Mousemove($pos[0] + 5,$pos[1] + 100)
MouseClick("left", $pos[0] + 5,$pos[1] + 100)
;Still disabled, I would need to send keystrokes.
_FFSetValue('test', $input, 'elements')

If somebody has an idea please ?

Kind Regards.

Edited by mario52

Share this post


Link to post
Share on other sites

By now my workaround is, might be useful for someone else :

$input = _FFXPath('//*[@id="searchInput"]')
$pos = _FFGetPosition($input)
Opt("WinTitleMatchMode", 2)
$win = "Mozilla Firefox"
BlockInput(1)
WinActivate($win, "")
Opt("MouseCoordMode", 2)
MouseClick("left", $pos[0] + 5,$pos[1] + 100, 1, 0)
Send("TEST")
BlockInput(0)

If someone as a better solution, please don't hesitate.

Thanks.

Share this post


Link to post
Share on other sites

I've been looking at this and haven't found a way to trigger the keyup event. One other option would be to enable the button manually, ie:

#include <FF.au3>

_FFConnect(Default, Default, 3000)

$sURL = "http://www.revillweb.com/demos/jQueryDisableButton/jqueryDisableButton.html"

_FFTabAdd($sURL)

;Fill the field but does not activate the button near
$input = _FFXPath('//*[@id="searchInput"]')
 _FFSetValue('test', $input, 'elements')

_FFCmd("window.content.document.getElementById('submitBtn').disabled = false")

Share this post


Link to post
Share on other sites

controlsend works (on your URL provided)...perform a .focus on your input, and then do something like this (was using IE)

#include <ie.au3>
$oIE = _IEAttach("jQuery enable")
$hWin = _IEPropertyGet($oIE,"hwnd")
WinActivate($hWin)
$oInput = _IEGetObjByName($oIE, "searchQuery")
$hControl = ControlGetHandle($hWin,"","[CLASS:Internet Explorer_Server; INSTANCE:1]")
$oInput.focus
$oInput.value = "something"
ControlSend($hWin, "", $hControl, "test")
$oInput.value = "something"

sets the value, sends some keys, re-set the value (for accuracy, and to remove the send text)

Else, you have to look into .fireEvent

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Hi,

Thanks for all your answer.

I tried all the above with FF.au3 because I am working with firefox not IE and it failed.

Here's the source code of the button :

<button class="lecture" ng-disabled="validate()" type="submit" disabled="disabled">Lire</button>

I tried :

_FFCmd("window.content.document.getElementsByClassName('lecture').disabled = false")

This :

_FFCmd("d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keypress',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);")
_FFCmd("d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keydown',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);")
_FFCmd("d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keyup',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);")

Still nothing for this button. I need to tabulate and fill in the infos to get it enabled.

Any help please ?

Thanks a lot !

Share this post


Link to post
Share on other sites

Can you post the jQuery code that gets executed on a keystroke? Also, post the results from the Scite output window from running the above commands.

Edit: Also please note that FFau3.xpath would need to have been set by a prior call to _FFXPath.

Edited by Danp2

Share this post


Link to post
Share on other sites

Hi,

I don't know how to get the code executed. Nothing was shown on the firefox console nor firebug. The most revelant thing I have see on firebug was that :

function email_validate() {
var field = document.getElementById('InputEmail00');
var verif = /^\s*([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,}\s*$/
if (verif.exec(field.value) == null){
return false;
}
return true;
}

When the regexpr condition is true the button is enabled. Something like abcd@ab.co enable the button.

For the rest here are the scite outputs

_FFCmd("window.content.document.getElementsByClassName('lecture').disabled = false")

_FFCmd("window.content.document.getElementsByClassName('lecture').disabled = false")
__FFSend: FFau3.WCD=window.content.top.document;
__FFRecv: [object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
[object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
__FFSend: try{window.content.top.document.getElementsByClassName('lecture').disabled = false}catch(e){'_FFCmd_Err';};
__FFRecv: 0
_FFCmd("d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keyup',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);")

__FFSend: FFau3.WCD=window.content.top.document;
__FFRecv: [object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
[object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//*[@id='account_email']",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: [object HTMLInputElement] - {querySelector: function() {...}, querySelectorAll: function() {...}, scrollTop: 0, scrollLeft: 0, scrollHeight: 34, scrollWidth: 256, clientTop: 1, ...}
__FFSend: try{d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keyup',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);}catch(e){'_FFCmd_Err';};
__FFRecv: 1


__FFSend: FFau3.WCD=window.content.top.document;
__FFRecv: [object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
[object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//*[@id='account_email']",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: [object HTMLInputElement] - {querySelector: function() {...}, querySelectorAll: function() {...}, scrollTop: 0, scrollLeft: 0, scrollHeight: 34, scrollWidth: 256, clientTop: 1, ...}
__FFSend: try{d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keydown',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);}catch(e){'_FFCmd_Err';};
__FFRecv: 1


__FFSend: FFau3.WCD=window.content.top.document;
__FFRecv: [object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
[object HTMLDocument] - {location: {...}, querySelector: function() {...}, querySelectorAll: function() {...}, evaluate: function() {...}, createExpression: function() {...}, createNSResolver: function() {...}, addEventListener: function() {...}, ...}
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//*[@id='account_email']",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: [object HTMLInputElement] - {querySelector: function() {...}, querySelectorAll: function() {...}, scrollTop: 0, scrollLeft: 0, scrollHeight: 34, scrollWidth: 256, clientTop: 1, ...}
__FFSend: try{d=FFau3.WCD.createEvent('KeyboardEvent');d.initKeyEvent('keypress',true,true,null,false,false,false,false,9,0);FFau3.xpath.dispatchEvent(d);}catch(e){'_FFCmd_Err';};
__FFRecv: 1

Thank you for your help.

:

Edited by mario52

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...