我正在尝试在纽约市健康筛查webiste上自动填写一张表格。问题是,它似乎会自动生成“您正在进入的学校或设施”条目的选项列表。选项列表似乎不能很好地放在页面源代码中,因为我可以在web上的示例中找到,其中每个选项都有自己的id。
我想知道如何使用javascript (也许是getElementById?)从列表中选择特定选项(本例中为学校位置)?
发布于 2020-10-05 10:47:56
以下是您可能会发现有用的一些示例AppleScript代码:
set targetURL to "https://healthscreening.schools.nyc/?type=G"
set guestIsStudent to true -- true or false
set guestFirstName to "John"
set guestLastName to "Doe"
set guestEmail to "johndoe@example.com"
set schoolFacility to "P.S. 452"
set guestLocationFloor to ""
tell application "Safari"
activate
make new document with properties {URL:targetURL}
tell application "System Events" to repeat until exists (buttons of ¬
UI elements of groups of toolbar 1 of window 1 of ¬
process "Safari" whose name = "Reload this page")
delay 0.5
end repeat
tell document 1
if guestIsStudent then
do JavaScript "document.getElementById('guest_isStudent').click();"
else
do JavaScript "document.getElementById('guest_isVisitor').click();"
end if
do JavaScript "document.getElementById('guest_first_name').value = '" & guestFirstName & "';"
do JavaScript "document.getElementById('guest_last_name').value = '" & guestLastName & "';"
do JavaScript "document.getElementById('guest_email').value = '" & guestEmail & "';"
do JavaScript "document.getElementById('guest_location_floor').value = '" & guestLocationFloor & "';"
do JavaScript "document.getElementsByClassName('k-icon k-i-arrow-60-down')[0].click();"
delay 1
tell application "System Events"
keystroke "P.S. "
delay 0.5
keystroke "452"
delay 0.5
key code 125 -- Down Arrow
delay 0.5
key code 36 -- Enter
end tell
if (do JavaScript "document.getElementsByClassName('k-textbox')[0].value;") is equal to schoolFacility then
-- # Click the Fill Out Daily Screening button.
do JavaScript "document.getElementsByClassName('btn btn-primary mt-2 btn-lg')[0].click();"
end if
end tell
end tellhttps://stackoverflow.com/questions/64195051
复制相似问题