janhoedt
asked on
Powershell Get item of html dropdown?
Hi,
This is exactly what I want to do:
https://stackoverflow.com/questions/15150397/powershell-select-drop-down-menu-from-web-page
= selecting an item in a dropdown list of html (reporting server)
Now my link is
http://OurReportingServer/Reports/Pages/Report.aspx?ItemPath=%2fConfigMgr_PRD%2fSoftware+Updates+-+C+Deployment+States%2fStates+1+-+Enforcement+states+for+a+deployment
And what I want to be selected is
($dropdown | where {$_.innerHTML -like "Updates - PILOT*"}).Selected = $true
How can I achieve this?
J.
This is exactly what I want to do:
https://stackoverflow.com/questions/15150397/powershell-select-drop-down-menu-from-web-page
= selecting an item in a dropdown list of html (reporting server)
Now my link is
http://OurReportingServer/Reports/Pages/Report.aspx?ItemPath=%2fConfigMgr_PRD%2fSoftware+Updates+-+C+Deployment+States%2fStates+1+-+Enforcement+states+for+a+deployment
And what I want to be selected is
($dropdown | where {$_.innerHTML -like "Updates - PILOT*"}).Selected = $true
How can I achieve this?
J.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great! However, the selection method should be different because the text appears to be (in the result of the query)
"Updates - PILOT - November - Updates - PILOT - November", so it is there twice and when selecting this $Option the submit does not find it.
Don't know why the text does this (enumerating twice) but tried to select on value
Tried $option = $($ie.Document.getElements ByTagName( 'OPTION') | Where-Object {$_.text -like $DropdownText}).uniquenumb er but that does not work
Any ideas?
"Updates - PILOT - November - Updates - PILOT - November", so it is there twice and when selecting this $Option the submit does not find it.
Don't know why the text does this (enumerating twice) but tried to select on value
Tried $option = $($ie.Document.getElements
Any ideas?
ASKER
I see there is an option $option.uniqueNumber but not suer how to fit this all together.
Sorry, can't quite follow your description of what's happening.
Does the script produce any errors, or is just IE / the site not cooperating?
What's the output when you just paste the following into a PS console?
Does the script produce any errors, or is just IE / the site not cooperating?
What's the output when you just paste the following into a PS console?
$ReportUrl = 'http://OurReportingServer/Reports/Pages/Report.aspx?ItemPath=%2fConfigMgr_PRD%2fSoftware+Updates+-+C+Deployment+States%2fStates+1+-+Enforcement+states+for+a+deployment'
$DropdownText = 'Updates - PILOT*'
$ie = New-Object -ComObject 'InternetExplorer.Application'
$ie.Visible = $true
$ie.Navigate($ReportUrl)
While ($ie.Busy) {Start-Sleep -Milliseconds 500}
$Option = $ie.Document.getElementsByTagName('OPTION') | Where-Object {$_.text -like $DropdownText}
$Option | select inner*, outer*, text
ASKER
Never mind, overlooked something. Works great, thanks a lot!
ASKER
Sidenote: any idea howto make this possible in an htlml only context (so <a> </a>)?
Similar to the above, only the TagName would be "A".
ASKER
Think you misunderstood. I'd need to make a webpage which is generated by Powershell. The link itself should point to the url which triggers the dropdownbox and submits.
Probably some javascript or something else to include into the webpage?
Probably some javascript or something else to include into the webpage?
ASKER
Didnt try it but this might work:
https://stackoverflow.com/questions/430237/is-it-possible-to-use-js-to-open-an-html-select-to-show-its-option-list
https://stackoverflow.com/questions/430237/is-it-possible-to-use-js-to-open-an-html-select-to-show-its-option-list
We need at least the ID of the dropdown