用于从剪贴板中的表自动填充活动浏览器窗口中的字段的脚本

Script to auto populate fields in active browser window from table in clipboard

本文关键字:浏览器 活动 窗口 脚本 填充 字段 剪贴板 用于      更新时间:2023-12-01

基本上,我想写一个脚本,将从outlook复制的表中的特定单元格粘贴到活动web表单中的相应字段中。

web表单URL将根据其唯一参考号CommentID进行更改,如以下示例中的986734所示:https://xxx.xxx.com.au/trisprod/comment_line/cmnt_action.cfm?CommentID=986734&刷新=真

当表格被粘贴到记事本中时,它被行和选项卡分隔:

编辑:我刚刚意识到,如果没有10个代表,我就无法发布图片,所以从outlook 复制粘贴

First name      Test
Last name       Test
Phone number    8888 8888
Email address   xxx@xxx.com.au
Response required   Yes
Route/line          180
From location       CBD
To location         XXX
Travel date         20/11/2013
Travel time         10:38 am
Comments    something something somethingsomething something somethingsomething something somethingsomething something somethingsomething something something

因此总共有11个字段:First name, Last name, Phone number, Email address, Response required(yes/no,true/false), Route/line, From location, To location, Travel Date, Travel timeComments

如果其中一个输入丢失,脚本将直接移动到下一个字段。

在firefox中使用Inspect Element (Q)函数后,以下捕获显示了前几个字段:![航向捕获][2]

页面的[HTML?![][3]][3]

无论使用何种浏览器,脚本都必须工作,因此firefox和IE.

因此,基本上,表格会被复制到剪贴板上,然后点击网页表单使其成为活动窗口,然后运行脚本将剪贴板数据粘贴到正确的字段中,最好是通过热键触发。

我是一个完全的Noob,很乐意研究,但甚至不知道该开始学习什么语言或搜索什么术语——我似乎只是在兜圈子。任何关于开始学习哪种语言的帮助,或任何可能有帮助的教程方向,都将不胜感激。提前感谢,如果标签不相关,则表示抱歉。

编辑,我刚刚意识到,如果没有10个代表,我就无法发布图片,所以从firefox:中的Inspect Element (Q)功能复制和粘贴

<form name="frmCmnt_actions2" method="post" target="_top" action="cmnt_action_update.cfm?Step=0&amp;Refresh=TRUE">
    <input name="CommentID" value="986734" type="hidden">
    <input name="SubmitOption" value="FWD" type="Hidden">
    <h3>Enter New Comment &nbsp;&nbsp; #986734</h3>
    <table border="0" cellpadding="2" cellspacing="1" width="100%">
        <tbody>
            <tr>
                <td class="TableHead"> <strong>Description:</strong><font color="#ff0000" size="-2">*</font> <br>
                    <font size="1">(max 4000 chars)</font> </td>
                <td class="smTable" colspan="2">
                    <textarea onfocus="this.rows=25" onblur="checkSize(this,4000);this.rows=8" name="Description" rows="8" cols="72" wrap="soft"></textarea>
                </td>
                <input name="DialogResponses" type="hidden">
            </tr>
            <tr>
                <td class="TableHead"><strong>Comment Type:</strong><font color="#ff0000" size="-2">*</font></td>
            </tr>
            <tr>
                <td class="tablehead">
                    <input name="RDDay" value="29" type="hidden">
                    <input name="RDMth" value="11" type="hidden">
                    <input name="RDYr" value="2013" type="hidden">
                    <strong>Reported:</strong> </td>
                <td colspan="2" class="smTable"><strong>29/11/2013</strong></td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Incident Date:</strong><font color="#ff0000" size="-2">*</font></td>
                <td colspan="2" class="smTable">
                    <input name="IncidentDay" id="IncidentDay" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,1,31,'Incident Day',true);" type="Text">
                    <input name="IncidentMth" id="IncidentMth" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,1,12,'Incident Month',true);" type="Text">
                    <input name="IncidentYr" id="IncidentYr" required size="4" maxlength="4" value="" onblur="checkIntegerWithinRange(this,2000,2099,'Incident Year',true);" type="Text">
                    <input name="IncidentDate" type="Hidden">
                    &nbsp;&nbsp;&nbsp;
                    <input class="Button" value="Today" onclick="setIncidentDateToToday();" type="Button">
                </td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Incident Time:</strong></td>
                <td colspan="2" class="smTable">
                    <input name="IncidentHr" id="IncidentHr" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,23,'Incident Hour',true);" type="Text">
                    <input name="IncidentMin" id="IncidentMin" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,59,'Incident Minute',true);" type="Text">
                    24 Hr</td>
                <input name="IncidentTime" type="Hidden">
            </tr>
            <tr>
                <td class="TableHead"><strong>Incident Location:</strong></td>
                <td colspan="2">
                    <input name="IncidentLocation" id="IncidentLocation" required size="30" maxlength="100" value="" type="Text">
                </td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Service Destination:</strong></td>
                <td colspan="2">
                    <input name="ServiceDestination" id="ServiceDestination" required size="30" maxlength="100" value="" type="Text">
                </td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Service Departure Time:</strong></td>
                <td colspan="2" class="smTable">
                    <input name="ServiceDepartureHr" id="ServiceDepartureHr" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,23,'Service Departure Hour',true);" type="Text">
                    <input name="ServiceDepartureMin" id="ServiceDepartureMin" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,59,'Service Departure Minute',true);" type="Text">
                    24 Hr</td>
                <input name="ServiceDepartureTime" type="Hidden">
            </tr>
            <tr>
                <td class="TableHead" width="20%"><strong>Service Direction:</strong><font color="#ff0000" size="-2">*</font></td>
                <td class="smTable" colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td>
                                    <input name="ServiceDirection" value="T" type="radio">
                                    Inbound&nbsp;&nbsp;</td>
                                <td>
                                    <input name="ServiceDirection" value="F" type="radio">
                                    Outbound&nbsp;&nbsp;</td>
                                <td>
                                    <input name="ServiceDirection" value="R" type="radio">
                                    Regional&nbsp;&nbsp;</td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    </td>
    </tr>
    <tr>
    <td class="TableHead">&nbsp;</td>
    <td class="smTable" colspan="2">
    <table border="0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr id="extra1_bus_busno" style="">
            <td class="smTable"><strong>Bus Number:</strong></td>
            <td class="smTable">
                <input name="BusNumber" id="BusNumber" size="10" maxlength="200" value="" type="text">
            </td>
        </tr>
        <tr id="extra1_bus_routecode" style="">
            <td class="smTable"><strong>Route:</strong></td>
            <td class="smTable">
                <input name="RouteName" id="RouteCode" size="10" value="" type="text">
                <input class="Button" value="Find" onclick="FindRoute();" type="Button">
            </td>
        </tr>
        </option>
            <option value="1182">1 </option>
            <option value="1025">2 </option>
            <option value="1026">3 </option>
            <option value="1045">4 </option>
            <option value="1047">5 </option>
            <option value="1048">6 </option>
            <option value="1049">7 </option>
        </select>
    </td>
    </tr>
    </tr>
    <tr>
        <td class="TableHead"><strong>Respondent:</strong> <font color="#ff0000" size="-2">*</font></td>
        <td colspan="2" class="smTable">
            <textarea name="RespondentName" id="RespondentName" rows="2" cols="60" wrap="soft" readonly onfocus="setRespondents();"></textarea>
            <br>
            <input checked="" name="ckEmail" type="Checkbox">
            &nbsp;Send an E-mail to the respondent
            <input name="radEmailOpt" checked="" type="Radio">
            Automatic
            <input name="radEmailOpt" onclick="CheckNavforEmail()" type="Radio">
            Pop-up (for attachments)
            <input value="" name="RespondentEmail" type="Hidden">
            <input name="blnEmail" value="Y" type="Hidden">
        </td>
    </tr>
    </td>
    </tr>
    <tr>
        <td colspan="3">
            <hr>
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>First Name:</strong> <font color="#ff0000" size="-2">*</font></td>
        <td class="smTable">
            <input name="CustName" size="25" maxlength="100" value="" type="Text">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Surname:</strong> <font color="#ff0000" size="-2">*</font></td>
        <td class="smTable">
            <input name="CustSurname" size="25" maxlength="100" value="" type="Text">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Title:</strong></td>
        <td class="smTable">
            <input name="CustTitle" size="10" maxlength="10" value="" type="Text">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Address:</strong></td>
        <td class="smTable">
            <input name="CustAddr" size="25" maxlength="100" value="" type="Text">
            <input name="PrefContact" value="A" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Suburb:</strong></td>
        <td class="smTable">
            <input name="CustSub" size="25" maxlength="100" value="" type="Text">
            <input name="CustPostCode" size="4" maxlength="4" value="" type="Text">
            <input class="Button" value="Find" onclick="FindSub('');" type="Button">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Email:</strong></td>
        <td class="smTable">
            <input name="CustEmail" size="25" maxlength="50" value="" type="Text">
            <input name="PrefContact" value="E" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Home Phone Number:</strong></td>
        <td class="smTable">
            <input name="CustHomePh" size="20" maxlength="20" value="" type="Text">
            <input name="PrefContact" value="H" checked="" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Work Phone Number:</strong></td>
        <td class="smTable">
            <input name="CustWorkPh" size="20" maxlength="20" value="" type="Text">
            <input name="PrefContact" value="W" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Mobile Number:</strong></td>
        <td class="smTable">
            <input name="CustMobPh" size="20" maxlength="20" value="" type="Text">
            <input name="PrefContact" value="M" type="radio">
            Preferred Contact Channel </td>
    </tr>

对于浏览器安全,这是一个成败攸关的选项。我知道你想要什么,但有些浏览器不允许这是一个安全问题。

我确信这不是最有说服力的解决方案,但它满足了我的需求。

无标题-消息(HTML)<可以替换为任何窗口标题,并且是数据复制的来源。>Firefox<是要发布到的窗口(因此有一个单独的IE脚本)。

以下是清除剪贴板以解决由于字段为空而导致的任何问题所必需的:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True

SendKeys的行为出现了一些问题,因为按键超过了处理器,导致了不一致和不可预测的结果。这通过>WScript.Sleep 100<行之间的命令。完整脚本:

Set Shell = WScript.CreateObject("WScript.Shell")
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 2}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 8}"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 5}"
WScript.Sleep 100
Shell.SendKeys "{LEFT 2}"
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 3}"
WScript.Sleep 100
Shell.SendKeys "{RIGHT 2}"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{LEFT 4}"
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 6}"
WScript.Sleep 100
Shell.SendKeys "{RIGHT 4}"
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 4}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB 2}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 12}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 10}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB 2}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB 4}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 7}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys "{ENTER}"
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 5}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{TAB 3}"
WScript.Sleep 100
Shell.SendKeys "PAX requested no response"
相关文章: