Web Automation

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
John.McCallister
Posts: 26
Last visit: Tue Jul 09, 2019 9:28 am

Web Automation

Post by John.McCallister »

Looking for some help on automating a website... I have tried several things without much luck.

Basically if I try to use

$ie = New-Object -ComObject "internetexplorer.application"
$ie.visible = $true
ie.navigate($url)
while ($ie.Busy -eq $true) { Star-Sleep -Seconds 1 }

$Status = $ie.Document.getElementById("StatusId")

I get an error "You cannot call a method on a null-valued expression.


Appears the website is loaded, then javascript is ran to fill out the forms.

What I want to do; is edit a few inputs on the page; and submit it. I haven't had much luck at all! Any help on this is greatly appreciated!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Web Automation

Post by jvierra »

Check the status of the result before trying to us it.
You didn't even load a web page.
  1. if($ie.Document){
  2.       $Status = $ie.Document.getElementById("StatusId")
  3. }else{
  4.       Write-Host 'web page not found'
  5. }
User avatar
John.McCallister
Posts: 26
Last visit: Tue Jul 09, 2019 9:28 am

Re: Web Automation

Post by John.McCallister »

Yeah... I am getting web page not found...

But it is indeed being opened by IE?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Web Automation

Post by jvierra »

Many, most, modern webpages cannot be screen scraped especially it they use Ajax.
User avatar
John.McCallister
Posts: 26
Last visit: Tue Jul 09, 2019 9:28 am

Re: Web Automation

Post by John.McCallister »

well that sucks.

what are my options?

im able to parse the results from web-invoke but I'm not sure how to search for the results i want.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Web Automation

Post by jvierra »

Web-invoke?
User avatar
John.McCallister
Posts: 26
Last visit: Tue Jul 09, 2019 9:28 am

Re: Web Automation

Post by John.McCallister »

Sorry was using my phone

$html = Invoke-WebRequest -uri $url
$Input = $html.ParsedHtml.IHTMLDocument3_getElementsByTagName("script") | Where { $_.type -eq 'text\javascript' } | where { $_.uniqueNumber -eq "37" } | select -ExpandProperty Text
User avatar
John.McCallister
Posts: 26
Last visit: Tue Jul 09, 2019 9:28 am

Re: Web Automation

Post by John.McCallister »

Any way to effectively search through the returned results?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Web Automation

Post by jvierra »

If the returned results a $null then no. YU have to be sure you are getting a result. Enumerating the document won't work if Office is not installed.
User avatar
John.McCallister
Posts: 26
Last visit: Tue Jul 09, 2019 9:28 am

Re: Web Automation

Post by John.McCallister »

I get a result...

PS C:\Users\jmcc> $RawInputs
var url = _rootUrl + "OsInstance/CheckUniqueness";
var ipAddress = function() {
var self = this;
if(viewmodel.ipAddressId() === '') {
self.Id = 0;
} else {
self.Id = viewmodel.ipAddressId();
}
if(viewmodel.ipHasEdit() == true) {
self.HasUpdate = (self.Id != 0);
}
self.Address = viewmodel.ipAddress();
self.Description = viewmodel.ipDescription();
self.Duplex = viewmodel.duplex();
self.Gateway = viewmodel.gateway();
self.LANPort = viewmodel.lanPort();
self.MACAddress = viewmodel.macAddress();
self.Network = viewmodel.network();
self.IPAddressTypeKey = viewmodel.ipAddressTypeId();
self.Model = viewmodel.model();
self.Speed = viewmodel.speed();
self.Subnet = viewmodel.subnet();
self.VendorName = viewmodel.vendorName();
self.IPAddressTypeName = viewmodel.ipAddressType();
}
var osiVm = function () {
var self = this;
var isDirtyHubbleClosure = function(fieldName) {
return function(value) {
value = $.trim(value);
if(value == null || value.length <= 0) {
return;
}
var fields = self.hubbleResetFields();
if($.inArray(fieldName, fields) >= 0) {
return;
}
self.hubbleResetFields.push(fieldName);
};
};
var loadByIdClosure = function(url, property) {
return function(id) {
var data = { id: id };
$.post(url, data, property);
};
};
self.hubbleResetFields = ko.observableArray([]);
self.CanEdit = ko.observable("true");
self.action = ko.observable("Save Changes");
self.hasBitNine = ko.observable(false);
self.id = ko.observable("534263");
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked