IE Automation, Field requires keyboard input

Welcome Forums General PowerShell Q&A IE Automation, Field requires keyboard input

This topic contains 6 replies, has 2 voices, and was last updated by

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #120490

    Participant
    Points: 19
    Rank: Member

    I'm working on automating a series of tests to perform after a software upgrade that simulates what a user would do by clicking and entering data into fields within Internet Explorer to ensure functionality.  The problem I have run into is, some fields I can set the value but it require a keystroke or otherwise the field is seen as empty.  So when I search, it doesn't search for what I've specified but rather returns 100's of results because it thinks the field is blank.  Without using send keys, does anyone have any suggestions on how to get around this?  I've tried Focus(), Select(), and SetActive() on the field but this also fails to register that there is data in that field.

    How I'm setting the value:

    $A = $IE.Document.IHTMLDocument3_getElementById('txtNumber')
    $A.setAttribute('value',"$Number")

    Element I am working with:

  • #120510

    Participant
    Points: 303
    Helping Hand
    Rank: Contributor

    Are you watching IE and see the data in the field? You need to figure out how it was developed. For instance, they could be looking for an event to do form validation, like onkeyup() or onblur() rather than doing validation on form submit. When you do it manually what happens? I see txtNumber, so if there is validation that it's a number, what happens if you type a letter and release the key (onkeyup())? Do you get a validation error? If not and you click to another field (onblur()), do you get a validation message then? For instance, if it's the second example you could try Focus() on txtNumber, set value, and then focus on the submit button or something to trigger an onblur() event to complete validation.

  • #120523

    Participant
    Points: 19
    Rank: Member

    Thanks for the reply Rob.  It accepts letters, numbers, and specials so it doesn't appear to validate characters.  When I manually enter a number, the classname changes from -empty to -not-empty.

    Here is the element again:

     input class="SearchCriteria ng-valid FieldValidateWrapper k-textbox k-input Input xj-text-editor ng-touched ng-dirty ng-valid-parse ng-empty"
     id="txtNumber" type="text" ng-blur="setLastFocus($event)" set-focus="focusOnNumber" ng-model="search_criteria.SEARCH_NUMBER"
     text-editor="" hide-zero=""
  • #120525

    Participant
    Points: 19
    Rank: Member

    Had to take out the greater than and less than for it to paste... operator error. 🙂

     

  • #120660

    Participant
    Points: 303
    Helping Hand
    Rank: Contributor

    Did you try what I suggested? Based on what you posted, it looks like there is a blur event ng-blur="setLastFocus($event)" which is most likely what is modifying the class. You should be able to Focus on the control, set the value and the set focus to any other control to fire the blur event. Additionally, you could just update the class with DOM as well:

    $A.Class = $A.Class -replace 'ng-empty', ng-not-empty'
    
  • #120792

    Participant
    Points: 19
    Rank: Member

    The events associated with the element are blur, change, cut, keydown and paste.  I've tried setting focus() from that field, setting the value, then set focus to another with no luck and I've also tried changing the class as well to not-empty.  There is also a SelectionStart and SelectionEnd property that is a count of digits in the field (1234567 = 7) and I've changed this as well to match the number I'm attempting to add without success.  Is there a way to manually trigger an event?  .FireEvent('event') returns true

  • #120849

    Participant
    Points: 303
    Helping Hand
    Rank: Contributor

    To be clear, this isn't really Powershell. You are working with the Document Object Model (DOM) which is traditionally called with JavaScript. I'm mentioning this because your searches should be more like "DOM key down event trigger" rather than "Powershell IE keydown". Based on this thread, you can call any event manually like you did before with .Blur():

    $A.setAttribute('value',"$Number");
    $A.keydown();
    $A.keypress();
    $A.keyup();
    $A.blur();
    

You must be logged in to reply to this topic.