Here is hyperlink code
<a href="javascript:void(1)" onclick="server_playOn(17,2, 'est', this);">
Example
</a>
Here is my current powershell code.
Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() }
$username = "user"
$password = "pass"
$ie = New-Object -object InternetExplorer.Application
$ie.visible=$true
$ie.FullScreen=$true
$ie.navigate(".shtml")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
trap [Exception]
{
# This will happen if you're already logged in
if($_.Exception.Message -eq "Property 'value' cannot be found on this object; make sure it exists and is settable." -Or $_.Exception.Message -eq "You cannot call a method on a null-valued expression.")
{
# Try and skip this error
continue; }
else {
# Fail for other Exceptions
Write-Host -ForegroundColor Red $_.Exception.Message; }
}
##if not logged in
Write-Host -ForegroundColor Green "Logging into example";
$ie.document.getElementById("username").value = "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.document.getElementById("frmLogin").submit()
start-sleep 5
$ie.navigate(".shtml")
##need to add click code here
Here is hyperlink code
<a href="javascript:void(1)" onclick="server_playOn(17,2, 'est', this);">
Example
</a>
Here is my current powershell code.
Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() }
$username = "user"
$password = "pass"
$ie = New-Object -object InternetExplorer.Application
$ie.visible=$true
$ie.FullScreen=$true
$ie.navigate("http://www.example./en/index.shtml")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
trap [Exception]
{
# This will happen if you're already logged in
if($_.Exception.Message -eq "Property 'value' cannot be found on this object; make sure it exists and is settable." -Or $_.Exception.Message -eq "You cannot call a method on a null-valued expression.")
{
# Try and skip this error
continue; }
else {
# Fail for other Exceptions
Write-Host -ForegroundColor Red $_.Exception.Message; }
}
##if not logged in
Write-Host -ForegroundColor Green "Logging into example.";
$ie.document.getElementById("username").value = "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.document.getElementById("frmLogin").submit()
start-sleep 5
$ie.navigate("http://www.example./en/link5.shtml")
##need to add click code here
Share
Improve this question
asked Jun 13, 2013 at 0:07
MowgliMowgli
3,51222 gold badges65 silver badges90 bronze badges
3
- 1 Just a thought, but if you don't mind using a 3rd party library to acplish this, then you could use something like the Selenium PowerShell eXtensions (sepsx.codeplex.). Selenium has a much better API for interacting with HTML Elements. – Roberto Hernandez Commented Jun 13, 2013 at 0:20
- Thanks robert. I'll keep in mind, if since I don't know how to use it but will give it try. – Mowgli Commented Jun 13, 2013 at 2:08
- @JPBlanc See the answer which is marked as accepted answer. – Mowgli Commented Jun 13, 2013 at 14:44
2 Answers
Reset to default 3Add these lines at the end of the script:
$link = @($ie.Document.getElementsByTagName('A')) | Where-Object {$_.innerText -eq 'Example'}
$link.click()
Another way could be
$ie.Document.parentWindow.execScript($Javascript, "javascript")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745003948a4605661.html
评论列表(0条)