1 votes

AppleScript /JS document.getElementsByClassName

J'ai fait un script pour remplir un manuel dans une page web interne, mais les développeurs de ma société ont changé le code et mon code ci-dessous ne fonctionne plus.

tell application "Safari" to tell window id theWINID to do JavaScript "document.getElementsByClassName('text-entry')[0].value=" & quoted form of myCaseNote in tab 1

Voici le code du champ de texte de la page

enter image description here

J'ai essayé plusieurs choses mais je n'arrive pas à changer le texte (dans la démo de l'image "texte que je dois passer").

Toute aide serait très appréciée

<div lobid="##" data="[object Object]" casenotedata="[object Object]" caseid="5sd4sd-sd55sd-5sds5-sds5-sdsd55s" class="css-bzgzwc"><div class="note-input css-1d9ma27" data-cy="note-input"><div class="textarea-container"><div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div></div></div><div class="note-toolbar css-o3el1q" data-cy="note-toolbar"><div class="buttons-container"><button class="add-note-button" type="button">Apply</button></div></div></div>
<div class="note-input css-1d9ma27" data-cy="note-input"><div class="textarea-container"><div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div></div></div>
<div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div>
<div class="textarea-container"><div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div></div>
<div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div>
<div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div>
<textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea>
<div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div>
<span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span>
<div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div>
<div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div>
<div class="textarea-container"><div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div></div>
<div class="note-input css-1d9ma27" data-cy="note-input"><div class="textarea-container"><div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div></div></div>
<div class="note-toolbar css-o3el1q" data-cy="note-toolbar"><div class="buttons-container"><button class="add-note-button" type="button">Apply</button></div></div>
<div lobid="iTunes" data="[object Object]" casenotedata="[object Object]" caseid="bf4ecda0-113e-11ec-944e-9bd3d18184e9" class="css-bzgzwc"><div class="note-input css-1d9ma27" data-cy="note-input"><div class="textarea-container"><div class="form-textarea-container css-9db1eh"><div class="form-textbox"><div class="form-textarea focused"><textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea></div><span id="form-textarea-123_label" class="form-textbox-label" aria-hidden="true">Note</span></div></div></div></div><div class="note-toolbar css-o3el1q" data-cy="note-toolbar"><div class="buttons-container"><button class="add-note-button" type="button">Apply</button></div></div></div>

cela fonctionne mais il semble que form-textarea-123 change tout le temps (les chiffres)

tell application "Safari"
    do JavaScript "document.getElementById('form-textarea-123').value = 'demo'" in current tab of window 1

end tell

le code actuel

<textarea aria-invalid="false" id="form-textarea-123" name="note-input-224" aria-labelledby="form-textarea-123_label" aria-describedby=""></textarea>

Cela ne fonctionne pas non plus :

do JavaScript "document.getElementById('form-textarea').innerText;" in current tab of window 1

1voto

user3439894 Points 52496

Voici quelques exemples exemple AppleScript code qui vous permettra d'avancer dans le processus d'automatisation d'une solution complète :

Exemple AppleScript code :

tell application "Safari"
    tell its current tab of window 1

        set foo to do JavaScript "document.getElementsByClassName('form-textbox')[0].innerHTML;"

        set targetID to my getID(foo)

        do JavaScript "document.getElementById('" & targetID & "').value = 'demo';"

    end tell
end tell

--  ## Handler ##

to getID(foo)
    set curTID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to " id="
    set foo to second text item of foo
    set AppleScript's text item delimiters to "\""
    set foo to second text item of foo
    set AppleScript's text item delimiters to curTID
    return foo
end getID

Note : Le <em>exemple </em><strong>AppleScript </strong><em>code </em>n'est que cela et sans aucun élément inclus <em>traitement des erreurs </em>ne contient pas d'éléments supplémentaires <em>traitement des erreurs </em>le cas échéant. Il incombe à l'utilisateur d'ajouter toute <em>traitement des erreurs </em>selon ce qui est approprié, nécessaire ou souhaité. Consultez le <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_control_statements.html#//apple_ref/doc/uid/TP40000983-CH6g-129232" rel="nofollow noreferrer"><strong>essayer </strong></a><em>déclaration </em>et <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_control_statements.html#//apple_ref/doc/uid/TP40000983-CH6g-129657" rel="nofollow noreferrer"><strong>erreur </strong></a><em>déclaration </em>dans le <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html" rel="nofollow noreferrer"><strong>Guide du langage AppleScript </strong></a>. Voir aussi, <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_error_xmpls.html#//apple_ref/doc/uid/TP40000983-CH221-SW1" rel="nofollow noreferrer"><strong>Travailler avec des erreurs </strong></a>. En outre, l'utilisation du <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW10" rel="nofollow noreferrer"><strong>délai </strong></a><em>commande </em>peut être nécessaire entre les événements, le cas échéant, par exemple <code>delay 0.5</code> , avec le <em>valeur </em>de la <em>délai </em>de manière appropriée.

LesApples.com

LesApples est une communauté de Apple où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres utilisateurs d'appareils Apple, poser vos propres questions ou résoudre celles des autres.

Powered by:

X