troubleshooting Question

Manipulate Web Page Via PowerShell

Avatar of Sam Jacobs
Sam JacobsFlag for United States of America asked on
PowershellCSSHTMLGoogleJavaScript
10 Comments2 Solutions130 ViewsLast Modified:
I'm looking to manipulate a web page via PowerShell when there is no id field on the HTML element.
Let's take Google as an example ... Some elements have an id:
Element with an id... and some don't - they only have a class (or multiple) name(s):
Element with only a class name
I can use the following code to change the CSS of an element with an ID:
$SiteURL = "https://www.google.com/"   
$google = New-Object -ComObject "InternetExplorer.Application"
$google.visible = $true
$google.Navigate2($SiteURL)
# wait until doc is loaded and ready
Write-Host "Waiting for document to load "
    while ($google.ReadyState -ne 4) {
        Write-Host "." -NoNewLine
        Start-Sleep 1
    }
$doc = $google.Document
$id = [System.__ComObject].InvokeMember("getElementById",[System.Reflection.BindingFlags]::InvokeMethod, $null, $doc, 'lga')
"Current CSS: $($id.style.csstext)"
$id.style.csstext = "display:none;"
... but how can I change the CSS of an element with only a class?
SOLUTION
Qlemo
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 2 Answers and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros