0

I am trying to write a PowerShell script to open up a window in chrome, go to google, enter text in the search bar, hit enter, and then retrieve all the links in an array. Here's my first attempt at the code:

$URI = "www.google.com" $HTML = Invoke-WebRequest -Uri $URI $SearchField = $HTML.ParsedHtml.getElementById('lst-ib') $SearchField.value = "green flowers" $SearchButton = $HTML.ParsedHtml.getElementsByName('btnK') $SearchButton.click(); //Grab links and store into array 

But when I try to run it I get this:

The property 'value' cannot be found on this object. Verify that the property exists and can be set. At line:4 char:1 + $SearchField.value = "green flowers" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException Method invocation failed because [System.DBNull] does not contain a method named 'click'. At line:6 char:1 + $SearchButton.click(); + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
1
  • On the real site, do you need to do a get or a post? Commented Jul 10, 2016 at 1:48

1 Answer 1

0
$Site = "www.google.com/search?q=green+flowers" $Test = Invoke-WebRequest -URI $Site $Test.Links | Foreach {$_.href } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.