![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | How to press a button in Inter Explorer Hi, I am trying to retrieve some information from a website.The code below starts Internet Explorer and navigates to the url. $MyAccount = "x" $MyPassword = "y" $Url = "http://www.z.com/login/" $Sb = new-object -com internetexplorer.application $Sb.visible = $true $Sb.navigate($Url) [int]$Count = 1 while( ($sb.Busy -eq "True") ) { $sb.Busy start-sleep -m 100 $Count = $Count + 1 if ( $Count -ge 100 ) { return "Error: Timeout loading logon page." } } Next I supply username and password: $Sb.document.getElementById("email").value = $MyAccount $Sb.document.getElementById("password").value = $MyPassword The problem is: I don't know how to press the submit button. Below is the page source. <div class="part"><h2>Login_</h2> <form action="/login/" class="nice" method="post" name="login"><input type="hidden" name="login" value="1" /> <div class="line"><label class="mylabel" for="email">E-mail:</label><div class="inputs"><div><input name="email" type="text" value="" /></div></div><br style="clear: both;" /></div> <div class="line"><label class="mylabel" for="password">Password:</label><div class="inputs"><div><input name="password" type="password" value="" /></div></div><br style="clear: both;" /></div> <div class="line"><label class="mylabel"></label><div class="inputs"><div><input alt="Submit" height="28" src="/static/btn_submit_black.png" type="image" width="89" /></div></div><br style="clear: both;" /></div> </form><a class="support" href="/login/forgotpassword.html?cont=*a6DsRGXJyB16ePRawUTioKeEuhqCqgRxgM0z8lix5pY_pHwosuHIkYHE1oKiWH6c7YXsSD_v_EJhcXWUDwrQW82DQTb_gegykjIpsGMt*syW99PifaMZQ_yR9i2QMcw" title="Forgot password?">Forgot password?</a><br /> <a class="support" href="/login/new.html?cont=*a6DsRGXJyB16ePRawUTioKeEuhqCqgRxgM0z8lix5pY_pHwosuHIkYHE1oKiWH6c7YXsSD_v_EJhcXWUDwrQW82DQTb_gegykjIpsGMt*syW99PifaMZQ_yR9i2QMcw" title="New user? Sign up!">New user? Sign up!</a><br /> </div></div> Any help is appreciated! regards Michiel |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: How to press a button in Inter Explorer Try this $ie.document.getElementById("ElementID").submit() You can take a look here to see a working example on "Automated Web forms" http://scriptolog.blogspot.com/2007/...web-forms.html ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: How to press a button in Inter Explorer I just tested this very thing out, and I had to do this to get it to work: $ie.document.getElementById("ElementID").click() What came next has me stuck. It shows a dialog titled Security Information that states "This page contains both secure and nonsecure items. Do you want to display the nonsecure items?". While this is displayed, $ie.busy is $true. I'm still looking but I thought I'd put it out there anyway. Does anyone know how to detect a dialog like this and automatically click the Yes button on it? -- Kirk Munro Poshoholic http://poshoholic.com "Shay Levi" <no@xxxxxx> wrote in message news:8766a944ce858c9efa6df04aae0@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: How to press a button in Inter Explorer On Nov 7, 3:55 pm, "Kirk Munro" <so...@xxxxxx> wrote:
answer way Kirk, but in reality, you should probably not be promoting automated responses to security dialogue prompts; if you must, at least automate the click for "no" (for this particular dialog). The best case is that an image will fail to load, but the worst case is that a cross-site scripting issue has allowed the injection of a <script> tag with malicious code. Yours paranoidly and semi-preachingly, - Oisin / x0n | ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||
| Guest | Re: How to press a button in Inter Explorer You're absolutely right Oisin, and I'm pretty sure it's just an image or some such as well. So suggestions on how to make it click No? The end result I'm looking for is just the same: detection and dismissal of that dialog. This isn't a high priority for me. It's just something I was looking at and I know I'll come across in the future so I figured I'd put the question out there now. -- Kirk Munro Poshoholic http://poshoholic.com "Oisin Grehan" <oising@xxxxxx> wrote in message news:1194470677.263276.79420@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: How to press a button in Inter Explorer "Shay Levi" wrote:
the wrong ElementID. For this page I had to use the form name at the beginning: $Sb.document.getElementById("login").submit()
script. Thanks guys! regards Michiel PS How can I find out that methods like submit() en click() exist for getElementById | ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: How to press a button in Inter Explorer Kirk Munro wrote:
Add it to your trusted sites list if you trust it. That would be my initial recommendation. --------------- Trevor Sullivan MCP | ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: How to press a button in Inter Explorer Michiel, When I was trying this out I entered the wrong element ID as well. It's really easy to discover that you've entered the wrong element ID. If you execute this: $ie.document.getElementById("ElementID") and nothing is output in PowerShell, meaning that $null is returned, then your element wasn't found. So to make your script more robust, you might want to break it up like this: $element = $ie.document.getElementById("ElementID") if ($element) { $element.submit() } else { # output some error here } Also, to answer your question about discovering if certain methods exist on an object in PowerShell, you need to use Get-Member. So in this case, if you want to see all methods and properties (there are a lot) on the element, just run this command: $element | Get-Member | more If you simply want to detect the existence of a particular method, do this instead: if ($element | Get-Member submit) { $element.submit() } elseif ($element | Get-Member click) { $element.click() } else { # error handling code } -- Kirk Munro Poshoholic http://poshoholic.com "MichielV" <MichielV@xxxxxx> wrote in message news:5FBFD2C4-EA38-43CB-A5C5-897C2DC5F72E@xxxxxx
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DEP closed the program when press "ctrl" button | bobpllus | Vista performance & maintenance | 1 | 04-16-2008 03:17 PM |
| Where is the Up a level button in Explorer? | SS | Vista General | 8 | 07-15-2007 07:40 AM |
| Up button in Explorer? | Andrea333 | Vista General | 11 | 03-23-2007 01:45 PM |
| Found a Windows Explorer Up button, but... | Richard Stallmann | Vista General | 0 | 03-12-2007 07:01 AM |
| Where is the up button in explorer? | Phil | Vista General | 19 | 01-17-2007 03:25 PM |