问题
Sorry if this is too easy of a question, but I'm fairly new to Windows Powershell and all of the tutorials I've looked at for dropdown lists show you how to display one to the user.
Anyway what I am trying to do is test my web application using Powershell. I need to change a dropdownlist to a specific choice, I can use the value or index to do this it doesn't matter to me.
Thanks for any help you can give.
回答1:
Turns out the easiest way to do it was to just set the value of the control to the index I wanted like this:
$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("mywebsite")
$ie.visible = $true
$doc = $ie.document
$listbox = $doc.getElementByID(listboxID)
$listbox.value = 1
This selects the first value in the list box. I have no idea how to tell what that value is if you don't already know it. Or select based off of text but I don't need that.
回答2:
How about using WatiN from PowerShell?
来源:https://stackoverflow.com/questions/5379922/select-option-on-dropdown-list-for-web-ui-testing-automation-in-windows-powershe