How Do I start

Welcome Forums General PowerShell Q&A How Do I start

This topic contains 2 replies, has 3 voices, and was last updated by

 
Keymaster
3 weeks, 3 days ago.

  • Author
    Posts
  • #125112

    Participant
    Points: 12
    Rank: Member

    Buddies,

    I am starting a project in which I need to automate a report building process.

    I am presented with a webpage, where in I need to automate the entering of the username and password, then hit Login.
    There are hyperlinks on the page wherein one of the Link says Explore Data. When clicked on this there is another section below it from where I need to select data from a filtered list.After the selection is made I need to click on a Button called Add Clause.

    Then need to click on Generate This will generate a excel report which needs to be exported to the desktop.

     

    I have started with the first step.

    $url = "https://x.x.x.x"
    $username="Test"
    $password="Test"

    $ie = New-Object -com internetexplorer.application;
    $ie.visible = $true;
    $ie.navigate($url);

    while ($ie.Busy -eq $true)
    {
    Start-Sleep -Milliseconds 1000;
    }
    $ie.Document.getElementById("login").value = $username
    $ie.Document.getElementByID("Passwd").value=$password
    $ie.Document.getElementById("Login").Click();

    < *selecting a link*>

    while($ie.busy) {sleep 1}
    $link = $ie.Document.getElementsByTagName('A') | where-object {$_.innerText -eq 'Click here'}
    $link.click()

    This snippet just opens the page but doesn't input the username and password.

    Can someone please help me out?

    Any help will be appreciated.

    Thanks,

    Kaustubh Kumar

  • #125199

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

    So, this is really not a PowerShell thing per se, and PowerShell isn't always the easiest way to do this. You're using a VERY old COM object from Internet Explorer, which is the only way PowerShell CAN do this, but it's not a modern programming API and it won't work in all situations. It can sometimes be easiest to submit data to the form directly using Invoke-WebRequest (which has examples in its help).

    If you Google "web scraping in powershell" you'll see a number of articles on this subject. They do get pretty detailed, but keep in mind that everything you're using is technically older than PowerShell, and going through several programming layers to make it work in PowerShell. So it can be pretty hit-or-miss. And you'll need to know a decent amount about Javascript programming, because that's basically how you interact with the Document Object Model. For example, the "text" property, versus the "value" property, might be useful in this exact situation.

    Finally, keep in mind that a better post title than "How do I start" can help the right people find your post here on the site. Anything more specific ("Need help filling in a web form," perhaps) can draw the right people to your question.

  • #125207

    Participant
    Points: 82
    Helping Hand
    Rank: Member

    Also have the browser's web developer tools in mind. They can show you the http queries.

You must be logged in to reply to this topic.