Using Powershell to access webpage

I have been using the followiing to manage webpages. I always look for an_element_ID by using eye browse in HTML code. Is there better way to do it? Thanks

$ie = New-Object -COM "InternetExplorer.Application"

$ie.visible = $true

$ie.navigate(http://www.website.com)

$ie.document.getElementByID('an_element_ID').value

$ie.document.getElementsByTagName('A')

February 17th, 2015 4:58pm

 better way to do what?  Look for an ID?  How do you know what ID you want.  This is not automatic.  You have to know in advance.

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 7:16pm

For example, there is a link or button on the page and I need to use below to go to the next page. How to find 'an_element_ID' (if exists)? What I do is right-click on the webpage and select "View source". Read the HTML code to look for it. I am looking for some software tools or something

$ie.document.getElementByID('an_element_ID').click()

February 17th, 2015 10:18pm

And how do you know which button is the right one?  The first one?  The last one?  The blue one?  How?

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 10:19pm

Don't know if it is the best way but I search the elements in web pages using the Developer Tools in browsers.

For example, in Chrome, CTRL+SHIFT+J opens developer console and navigating each elements in Element tab is easier to find out which html tag represent what you are seeing in the browser.

See details here.

https://developer.chrome.com/devtools/docs/dom-and-styles#inspecting-elements

February 17th, 2015 10:31pm

Computer instructions have to be more specific than that.

You can search by tag name but how would you know, eyes closed, which tag is the correct one?

$ie.document.getElementsByTagName('input') |
   ForEach-Object{ $_.Value }

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 10:40pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics