Page 1 sur 1

événements javascript utilisant avec autoit

Posté : mer. 29 mars 2017 15:30
par davinciomar
Bonjour a tous. J'ai cherché sur internet et j'ai trouve des methodes pour lancer un javascript pour ma page.
Sont les suivants:
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
   Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <IE.au3>

;Visible METHOD 1: Using _IEAction to focus on input, enter "test" using _IEFormElementSetValue and then _IEAction blur to simulate loss of focus to trigger the "onblur" event

$oIE = _IECreate(@ScriptDir & "/example.html")
$oIE_Form = _IEGetObjByName($oIE, "form")
$oIE_Input = _IEFormElementGetObjByName($oIE_Form, "fname")
_IEAction($oIE_Input, "focus")
_IEFormElementSetValue($oIE_Input, "test")

_IEAction($oIE_Input, "blur")

ConsoleWrite("Visible mode result 1: "&_IEFormElementGetValue($oIE_Input)&@CRLF)

_IEQuit($oIE)

Sleep(500)

;Visible METHOD 2: Using _IEAction to focus on input, enter "test" using ControlSend and then _IEAction blur to simulate loss of focus to trigger the "onblur" event

$oIE = _IECreate(@ScriptDir & "/example.html")
$oIE_Form = _IEGetObjByName($oIE, "form")
$oIE_Input = _IEFormElementGetObjByName($oIE_Form, "fname")
_IEAction($oIE_Input, "focus")

$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "test")

_IEAction($oIE_Input, "blur")

ConsoleWrite("Visible mode result 2: "&_IEFormElementGetValue($oIE_Input)&@CRLF)

_IEQuit($oIE)

Sleep(500)

;Visible METHOD 3: Using _IEAction to focus on input, enter "test" using _IEFormElementSetValue and then ControlSend {TAB} to simulate loss of focus to trigger the "onblur" event

$oIE = _IECreate(@ScriptDir & "/example.html")
$oIE_Form = _IEGetObjByName($oIE, "form")
$oIE_Input = _IEFormElementGetObjByName($oIE_Form, "fname")
_IEAction($oIE_Input, "focus")

_IEFormElementSetValue($oIE_Input, "test")

$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{TAB}")

ConsoleWrite("Visible mode result 3: "&_IEFormElementGetValue($oIE_Input)&@CRLF)

_IEQuit($oIE)

Sleep(500)

;Hidden METHOD 1: Using _IEAction to focus on input, enter "test" using _IEFormElementSetValue and then _IEAction blur to simulate loss of focus to trigger the "onblur" event

$oIE = _IECreate(@ScriptDir & "/example.html", 0, 0, 1, 0)
$oIE_Form = _IEGetObjByName($oIE, "form")
$oIE_Input = _IEFormElementGetObjByName($oIE_Form, "fname")
_IEAction($oIE_Input, "focus")

_IEFormElementSetValue($oIE_Input, "test")

_IEAction($oIE_Input, "blur")

ConsoleWrite("Hidden mode result 1: "&_IEFormElementGetValue($oIE_Input)&@CRLF)

_IEQuit($oIE)

Sleep(500)

;Hidden METHOD 2: Using _IEAction to focus on input, enter "test" using ControlSend and then _IEAction blur to simulate loss of focus to trigger the "onblur" event

$oIE = _IECreate(@ScriptDir & "/example.html", 0, 0, 1, 0)
$oIE_Form = _IEGetObjByName($oIE, "form")
$oIE_Input = _IEFormElementGetObjByName($oIE_Form, "fname")
_IEAction($oIE_Input, "focus")

$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "test")

_IEAction($oIE_Input, "blur")

ConsoleWrite("Hidden mode result 2: "&_IEFormElementGetValue($oIE_Input)&@CRLF)

_IEQuit($oIE)

Sleep(500)

;Hidden METHOD 3: Using _IEAction to focus on input, enter "test" using _IEFormElementSetValue and then ControlSend {TAB} to simulate loss of focus to trigger the "onblur" event

$oIE = _IECreate(@ScriptDir & "/example.html", 0, 0, 1, 0)
$oIE_Form = _IEGetObjByName($oIE, "form")
$oIE_Input = _IEFormElementGetObjByName($oIE_Form, "fname")
_IEAction($oIE_Input, "focus")

_IEFormElementSetValue($oIE_Input, "test")

$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{TAB}")

ConsoleWrite("Hidden mode result 3: "&_IEFormElementGetValue($oIE_Input)&@CRLF)

_IEQuit($oIE)
Mon page est la suivant:
<!DOCTYPE html>
<html>
<body>

<p>Click the button to trigger a function that will output "Hello World" in a p element with id="demo".</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>
Je veux adapter le code a ma page c'est possible je vais utiliser un bouton et quand je touche le bouton, ma page changera le texte pour Hello World.
Merci d'avance.

Re: événements javascript utilisant avec autoit

Posté : mer. 29 mars 2017 16:10
par orax
#include <IE.au3>
$oIE = _IECreate(@ScriptDir & "\example.html")
$oIE.document.querySelector("button").click()
Le code simule un clic sur le premier élément "button".

Re: événements javascript utilisant avec autoit

Posté : dim. 09 avr. 2017 23:47
par davinciomar
affiche moi tout le temps
the resquested action with this object has failed

Re: événements javascript utilisant avec autoit

Posté : lun. 10 avr. 2017 18:28
par orax
C'est lié à la sécurité d'Internet Explorer. Si la page est stockée localement et si le mode protégé est activé, alors ça affichera : Internet Explorer a restreint l'exécution des scripts...
Si le fichier est hébergé il n'y a pas ce problème.

Une solution est d'ajouter un marqueur dans le fichier HTML.

Code : Tout sélectionner

<!DOCTYPE html>

<!-- saved from url=(0014)about:internet -->

<html>
Liens sur le sujet :
Enhanced Protected Mode and Local Files – IEInternals
Mark of the Web (Internet Explorer)

Re: événements javascript utilisant avec autoit

Posté : ven. 21 avr. 2017 18:04
par davinciomar
d'accord je vais vérifier ca.

Re: événements javascript utilisant avec autoit

Posté : lun. 24 avr. 2017 19:20
par davinciomar
orax a écrit : lun. 10 avr. 2017 18:28 C'est lié à la sécurité d'Internet Explorer. Si la page est stockée localement et si le mode protégé est activé, alors ça affichera : Internet Explorer a restreint l'exécution des scripts...
Si le fichier est hébergé il n'y a pas ce problème.

Une solution est d'ajouter un marqueur dans le fichier HTML.

Code : Tout sélectionner

<!DOCTYPE html>

<!-- saved from url=(0014)about:internet -->

<html>
Liens sur le sujet :
Enhanced Protected Mode and Local Files – IEInternals
Mark of the Web (Internet Explorer)
mais je peux cliquer un bouton sur ma page avec la id de ce bouton? par example j'ai deux bouton le premier s'appelle "un" et le second "deux". Je peux choisir quel bouton je veux cliquer?

Et par example je peux obtenir la id de mon bouton par example chercher la id.
$oObject = _IEGetObjById($oIE, "monbouton")
et apres cliquer mon bouton $oIE.document.querySelector($oObject).click()

c'est pas possible?