2

I am trying to select an item from a drop down menu in the HTML below.

<select class="select" name="expiration">
<option value="N" selected="selected">Never</option>
<option value="10M">10 Minutes</option>
<option value="1H">1 Hour</option>
<option value="1D">1 Day</option>
<option value="1W">1 Week</option>
<option value="2W">2 Weeks</option>
<option value="1M">1 Month</option>

Here is my current code. I don't receive any errors, just the item doesn't get selected.

# Code to select menu item
$ie = New-Object -comobject InternetExplorer.Application 
$ie.visible = $False

# navigate to URL
$ie.navigate('http://URL')
while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 1000; }

$expiration = $ie.Document.getElementsByClassName('expiration')
$expiration.outerText |Select-Object -Index 2
$ie.Document.getElementById('submit').Click()
Start-Sleep -Milliseconds 1000
$result = $ie.LocationURL
3
  • did you try - $expiration.Options.SelectedIndex = 2 ? Commented Nov 6, 2015 at 12:33
  • Yes, The property 'SelectedIndex' cannot be found on this object. Verify that the property exists and can be set. Commented Nov 7, 2015 at 13:05
  • $expiration = $ie.Document.getElementsByClassName('expiration') what is the value of $expiration after this line ? The class on your select element is select not expiration. Moreover I don't think you can select an element in a list on a webpage with PO's Select, it will only filter what you pipe to it but not act on the webpage Commented Nov 8, 2015 at 9:30

1 Answer 1

3

Try this :

$ie = New-Object -ComObject InternetExplorer.Application 
$ie.Visible = $False
$ie.navigate("http://URL")
while ($ie.Busy) { Start-Sleep -Milliseconds 1000 }

$expiration = $ie.Document.getElementsByClassName("select")
$expiration.Options.SelectedIndex = 2
$ie.Document.getElementById("submit").Click()
Start-Sleep -Milliseconds 1000
$result = $ie.LocationURL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.