Necesito un script para abrir cada pestaña en Safari cuando obtengo "valueIneed" de un sitio web interno
aquí está la etiqueta HTML
<td class="orderDetails">
<p class="details">
(My Certificate)
</p>
esto es lo que intenté esto pero esto está fallando
tell application "Safari"
do JavaScript "
var forgiveStatus = document.querySelector('class[details\"(My Certificate).innerHTML;
" in current tab of first window
set checkvalue to (do JavaScript "theStatus;" in current tab of first window) as string
end tell
para obtener más información, podría tener varias instancias de la misma etiqueta, y necesito abrir cada una en una nueva pestaña, o mejor aún, hacer clic en ellas una tras otra
No ha cerrado ninguna comilla ni paréntesis. Necesita los siguientes cuatro caracteres.
var theStatus = document.querySelector('class[details="(valueIneed)"]')
^^^^
Esto ahora es JavaScript sintácticamente correcto. Todavía dudo que haga lo que necesita, pero sin ver el DOM de la página en la que está ejecutando esto y una descripción completa del problema, no puedo decirlo con certeza.
Dada la actualización de su pregunta con un fragmento de HTML, el código que está intentando no funcionará. Para obtener el HTML interno del elemento, use el siguiente JavaScript:
document.querySelector("td.orderDetails .details").innerHTML;
property tmp : "~/Desktop/safarihtml.html"
set htmls to {}
tell application "Safari" to tell window 1 to if exists then ¬
set htmls to do JavaScript ¬
"Array.from(document" & ¬
" .getElementsByClassName('details'))" & ¬
" .map(x=>x.innerHTML);" in current tab
repeat with html in htmls
newTabWithHTML(html)
end repeat
on newTabWithHTML(html)
local html
set furl to URL of tmpfile()
set eof of (tmpfile() as alias) to 0
write html to (tmpfile() as alias) as «class utf8»
tell application "Safari" to tell ¬
(a reference to window 1)
if not (exists) then make new document
set current tab to make new ¬
tab with properties ¬
{URL:furl}
repeat until name of current tab ¬
≠ "Untitled"
delay 1
end repeat
end tell
delete tmpfile()
end newTabWithHTML
on tmpfile()
tell application "System Events"
set f to a reference to the file tmp
if not (exists f) then (make new file ¬
with properties {name:tmp})
return f
end tell
end tmpfile
mateusz szlosek
querySelector
la función. Me parece que falta el soporte de cierre allí. Estos son ejemplos del uso adecuado: developer.mozilla.org/en-US/docs/Web/API/Document/querySelectormateusz szlosek
<p class="details">
necesita llamardocument.querySelector(".details").innerHTML