Reputation: 123
I have a website that has a button that does not become active until an option is selected. But I select an option and the button still wont become active, unless I physically click on it. I was thinking of using the send-key vb style to the powershell script, but heard its not recommended because of focus issues. [System.Windows.Forms.SendKeys]::SendWait(“{ENTER}”)
This is what i have tried and didnt work for me. ( I'm able to change the list options, but cant click the button because it's grayed out). i see its using some type of xml 1.0, could i do something with that, or "Go_NextPage(document.FORM.Class)"
.
Powershell:
$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.navigate("http://website/address")
$ie.visible =$true
While ( $ie.busy -eq $true){
[System.Threading.Thread]::Sleep(1000)
}
$doc = $ie.document
$type = $doc.getElementById("class")
#$type.click() << was seeing if i could click it even though its not a button.
$type.value = "7"
$bt = $doc.getElementsByTagName("input") |
Where-Object {$_.Name -eq "Class_Button"}
$bt.click() # but is grayed out
HTML CODE:
<td>
<select name="Class" id="Class" size="1">
<script language="JavaScript" type="text/javascript">
//<![CDATA[
AdrTypeList();
//]]>
</script>
<option value="2">Some </option>
<option value="3">Thing </option>
<option value="7">File
</option></select>
<input type="button" class="ButtonEnable" name="Class_Button"
id="Class_Button" value="Set " onclick="Go_NextPage(document.FORM.Class)">
</td>
Upvotes: 0
Views: 2302
Reputation: 1946
My answer below is based on my experience testing the sample PowerShell and HTML on my local machine. While the changes I've mentioned below work on my machine... clicking the button here obviously does nothing so I can't 100% guarantee it'll work on your end.
I am fairly certain that the string passed into 'getElementById' is case sensitive, so 'class' is different to 'Class'.
In my testing of your code, I initially get a null object back until I change the capitalization.
The next thing you'll find is that that method returns a collection (in this case a collection of one), so you'll need to reference the specific object in order to set the value property (e.g. $type[0].value = "7"
)
Finally, the object returned by 'getElementByTagName' didn't appear to be giving you all the info (or methods) you were expecting. Specifically for me there was no Name value nor a click method.
Instead of using the tagname and a where statement, I'd suggest going direct to the name:
$doc.IHTMLDocument3_getElementsByName('Class_Button')
( $doc.getElementsByName('Class_Button')
didn't work for me, and I've seen plenty of people suggest using the ITHMLDocument3 methods by default anyway.)
The moral of this is to sanity check your code. Run a line and double check that what you expect to be returned is actually returned, try running the method without assigning it to a variable to see if it outputs to the prompt correctly.
Upvotes: 1