Julia-IT-SG
Julia-IT-SG

Reputation: 47

powershell can not click click a button

Here is the PS code

$url="http://site.example"
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate($url)

but I want to click on button (Play Now)

Here is the HTML code

<div data-a-target="lb-core-button-label-text" class="lb-flex-grow-0">Play Now</div>

any suggesting please

Upvotes: 1

Views: 496

Answers (1)

postanote
postanote

Reputation: 16086

Sure, you can use Powershell to click things on a web page, but you have to explicitly tell it to, using the target element and method.

For example:

# Get all the needed elements
# Scrape the page
$Pwpush = Invoke-WebRequest -Uri 'https://pwpush.com'
$Pwpush.Content
$Pwpush.AllElements
$Pwpush.Forms
$Pwpush.InputFields
$Pwpush.AllElements.FindById('password_payload')
$Pwpush.AllElements.FindByName('commit')


# Full run using the target elements
$password = '1234'
$loginUrl = 'https://pwpush.com'

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

while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1 }

($ie.document.getElementById('password_payload') | 
select -first 1).value = $password
Start-Sleep -Seconds 1 

$ie.Document.getElementsByName('commit').Item().Click();
Start-Sleep -Seconds 1 

Of course, those pauses are not always necessary, but I have them there just as a delay to see what is happening and to make sure render has completed before taking the next action(s)

Upvotes: 2

Related Questions