How to reduce Python selenium Pyperclip.paste execution time

后端 未结 1 1342
后悔当初
后悔当初 2021-01-25 05:37

I am using following python script to copy contents from a local file and paste it into text-area, which actually works fine. However, it takes lots of time to complete this tas

相关标签:
1条回答
  • 2021-01-25 06:03

    If your goal is solely Task Automation you could speed up the typing by writing a function and pass the element and the text setting the field directly with a script injection as follows :

    def set_text(element, text):
      element._parent.execute_script("""
        var elm = arguments[0], text = arguments[1];
        if (!('value' in elm))
          throw new Error('Expected an <input> or <textarea>');
        elm.focus();
        elm.value = text;
        elm.dispatchEvent(new Event('change'));
        """, element, text)
    
    0 讨论(0)
提交回复
热议问题