在网页输入框中自动填充值的脚本 [英] Script to fill a value automatically in the webpage input box

查看:425
本文介绍了在网页输入框中自动填充值的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作是为患者订购诊断测试,我需要为每个诊断测试写6-7个字符的值.我有24个不同的值,我需要填写数千次.我正在考虑使用Tampermonkey创建24个不同的脚本,以通过单击脚本框来加快我的工作.所以事情是我需要填补这个.这是控制台中的输入ID和该框的所有内容.然后,我手动输入值,每次弹出一个字符(与google或youtube搜索框的原理相同)时,弹出列表都会更新,这是

My job is to order diagnostic tests for patients and I need to write 6-7 characters value for each diagnostic test. I have 24 different values and I need to fill it many thousands of times. I am thinking to create 24 different scripts with Tampermonkey to speed up my job by clicking on the script box. So the thing is that I need to fill this box. Here are the input id and everything of that box in the console. Then I type the value manually, I get popup list which updates every time I type one character (same principle as google or youtube search box), here is the popup list after I type a value and if I want that diagnostic test, I need to click on it from the popup list, I cannot just simply click enter. So this is the code I have to fill the box by a value:

document.body.appendChild(element)element.addEventListener('click',function(){document.querySelector("input#generic_test_order_search.ui-autocomplete-input").value ='15002'})

该脚本填充了值,但没有出现弹出列表,我需要单击该框,删除一个字符,然后再次写入以获得一个列表,然后从中选择一个诊断测试.仍然很费时间.

The script fills the value, but the popup list doesn't appear and I need to click on the box, delete one character and write it again to get a list and then to choose a diagnostic test from it. Still, time-consuming.

我想知道,是否可以使脚本从列表中自动添加诊断测试,例如这个例子?如果不是,是否有可能使该弹出列表出现,而我不需要单击该框,删除一个字符然后再次写它?至少,我可以确定在填充值后单击该框吗?我尝试了以下代码,但不起作用: document.querySelector("input#generic_test_order_search.ui-autocomplete-input").click()

I wonder, is it possible to make a script to add automatically a diagnostic test from the list like this example? If no, is it somehow possible to make that popup list would appear and I won't need to click on the box, delete one character and write it again? At least, could I make that the box is clicked after a value has been filled? I tried this code but doesn't work: document.querySelector("input#generic_test_order_search.ui-autocomplete-input").click()

请帮助我使其尽可能自动化,从长远来看将为我节省数百小时.

Please help me to make it as automatic as possible, which would save me hundreds of hours in the long-term.

推荐答案

1-至于问题的第二部分.图片4.

1 - As for the second part of the question. Picture 4.

为要删除的参数自动填充非常简单,我们可能只需要元素的html代码即可.

It is pretty simple to make an auto-fill for the dropping parametres, we just might need the html-code of the elements.

例如,

  • document.getElementsByTagName('input')[0] .click(); 从第一个输入中单击第一个输入复选框
  • document.getElementsByTagName('select')[0] .selectedIndex = 1; 从第一个选择中选择第二个值
  • document.getElementsByTagName('button')[0] .click(); 单击第一个按钮
  • document.getElementsByTagName('input')[0].click(); clicks the first input checkbox from the first input
  • document.getElementsByTagName('select')[0].selectedIndex = 1; selects the second value from the first select
  • document.getElementsByTagName('button')[0].click();clicks the first button

为了更加精确,您可以先使用class,然后使用tag:例如, document.getElementsByClassName('testClassDependingOnExistingClasses')[0] .getElementsByTagName('button')[0] .click(); .

To make it more precise you might use class at first, at then tag: document.getElementsByClassName('testClassDependingOnExistingClasses')[0].getElementsByTagName('button')[0].click(); for example.

在诸如此类的页面上执行的任何手动操作都可以使用JS自动完成.

Anything you do manually on a page like that can be done automatically with JS.

2-至于问题的第一部分.图片2这是答案的一部分.如何在js中触发向下箭头键?

2 - As for the first part of the question. Picture 2. Here is the part of the answer. How to trigger arrow down press in js?

也许此代码可能会有所帮助,但信息不足,因为所放置元素的html代码上没有数据.

Maybe this code might help, but not enough information, since no data on html-code of the dropped elements.

document.getElementById('generic_test_order_search').clildren [0] .click();

这篇关于在网页输入框中自动填充值的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆