Powershell不能单击单击按钮

时间:2019-12-21 20:26:37

标签: windows powershell

这是PS代码

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

但是我想单击按钮(立即播放)

这是HTML代码

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

请提出任何建议

1 个答案:

答案 0 :(得分:0)

当然,您可以使用Powershell单击网页上的内容,但是必须使用目标元素和方法明确地告诉它。

例如:

# 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 

当然,这些暂停并非总是必要的,但是我将它们停在那里,只是为了延迟查看发生的情况并确保渲染已完成,然后再执行下一步操作