locked
Ie automation with powershell // drop down tables RRS feed

  • Question

  • Hello All,

    I am creating an Ie automation script using the InternetExplorer.Application com object in pwershell. I am stuck on line 18 - 20 (  $submit1 = $doc.getElementById("ucReportbuilder_reports") .)

    The drop down table requires me to select the option in the table , and upon clicking it, will load more options. So doing a straight .value = "option" will not load the other subsequent tables. I need to know how to "activate" an option. Here is the html

    <select tabindex="1" id="ucReportBuilder_reports" language="javascript" onchange="__doPostBack('ucReportBuilder$reports','')" name="ucReportBuilder:reports">
          <option value="Select a Report">&lt;Select a Report&gt;</option>
          <option value="Report 1">Report 1 Test</option>
          <option value="Report 2"></option>
          </select>

    The psh code is below, thanks
    ======================
    $ie = New-Object -com "InternetExplorer.Application"
    $ie.Navigate("https:/somedomain.com/login.aspx")
    $ie.visible = $true

    do { sleep 5 }
    while ( $ie.busy )

    $doc = $ie.document
    $user = $doc.getElementById("ucLogin_txtBoxUsername")
    $password = $doc.getElementById("ucLogin_txtBoxPassword")
    $user.value = "usr"
    $password.value = "abc123"
    $submit = $doc.getElementById("ucLogin_cmd_login").click()

    do { sleep 5 }
    while ( $ie.busy )

    $submit1 = $doc.getElementById("ucReportbuilder_reports")
    $submit1.value=("Report2")


    do { sleep 5 }
    while ( $ie.busy )

    $datefrom =  (get-date).AddDays(-31)
    $datefromformatted = get-date -date $datefrom -format MM/dd/yyyy
    $dateto = (get-date).AddDays(-1)
    $datetoformatted = get-date -date $dateto -format MM/dd/yyyy
    $submit2 = $doc.getElementById("ucReportbuilder_dtm_from_date")
    $submit2.value = "$datefromformatted"
    $submit3 = $doc.getElementById("ucReportbuilder_dtm_to_date")
    $submit3.value = "$datetoformatted"
    $submit4 = $doc.getElementById("ucReportbuilder_format")
    $submit4.value = "csv"
    Wednesday, August 3, 2011 2:46 PM

Answers

  • well, looking at MSDN, the GetElementByID returns a HTMLElement object which has a method called SetProperty, but it gives no indication if it fires events or not.

    It also has an Invoke method, which could be used to invoke the OnChange event after you've changed the value. I guess you'd jsut do

    $submit1.invoke("onchange")

    im not sure if this will work since i found it more so when looking for javascript, but in javascript you can call its onchange so try

    $submit1.onchange()

    also might need to repopulate the onchange event (or at least play around with it if you dont get what you expect)

    $submit1.onchange = "function() {alert('test');};"

    other than that, im not sure.. not much of an HTML dev guy


    Justin Rich
    http://jrich523.wordpress.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, August 3, 2011 3:19 PM

All replies

  • well, looking at MSDN, the GetElementByID returns a HTMLElement object which has a method called SetProperty, but it gives no indication if it fires events or not.

    It also has an Invoke method, which could be used to invoke the OnChange event after you've changed the value. I guess you'd jsut do

    $submit1.invoke("onchange")

    im not sure if this will work since i found it more so when looking for javascript, but in javascript you can call its onchange so try

    $submit1.onchange()

    also might need to repopulate the onchange event (or at least play around with it if you dont get what you expect)

    $submit1.onchange = "function() {alert('test');};"

    other than that, im not sure.. not much of an HTML dev guy


    Justin Rich
    http://jrich523.wordpress.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, August 3, 2011 3:19 PM
  • This reply is wrong, the element returned by getelementbyid is a com object, not HTMLElement .

    there is no such 'invoke' method in this com-object.tById

    Tuesday, June 24, 2014 10:01 AM
  • Solution:

    1. in winform web browser  to cause postback

    $element.invokeMember('onchange')

    2. in ie com-object

    $ie.document.parentwindow.exescript('_dopostback.....')

    Wednesday, June 25, 2014 1:54 AM