événements javascript utilisant avec autoit

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
davinciomar
Niveau 2
Niveau 2
Messages : 17
Enregistré le : dim. 26 mars 2017 19:52
Status : Hors ligne

événements javascript utilisant avec autoit

#1

Message 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.
Avatar du membre
orax
Modérateur
Modérateur
Messages : 1479
Enregistré le : lun. 23 mars 2009 04:50
Localisation : ::1
Status : Hors ligne

Re: événements javascript utilisant avec autoit

#2

Message 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".
De petits détails peuvent faire toute la différence. — Quand la boule de neige commence à rouler… poussez-la. (Columbo)
davinciomar
Niveau 2
Niveau 2
Messages : 17
Enregistré le : dim. 26 mars 2017 19:52
Status : Hors ligne

Re: événements javascript utilisant avec autoit

#3

Message par davinciomar »

affiche moi tout le temps
the resquested action with this object has failed
Avatar du membre
orax
Modérateur
Modérateur
Messages : 1479
Enregistré le : lun. 23 mars 2009 04:50
Localisation : ::1
Status : Hors ligne

Re: événements javascript utilisant avec autoit

#4

Message 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)
De petits détails peuvent faire toute la différence. — Quand la boule de neige commence à rouler… poussez-la. (Columbo)
davinciomar
Niveau 2
Niveau 2
Messages : 17
Enregistré le : dim. 26 mars 2017 19:52
Status : Hors ligne

Re: événements javascript utilisant avec autoit

#5

Message par davinciomar »

d'accord je vais vérifier ca.
davinciomar
Niveau 2
Niveau 2
Messages : 17
Enregistré le : dim. 26 mars 2017 19:52
Status : Hors ligne

Re: événements javascript utilisant avec autoit

#6

Message 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?
Répondre