【问题标题】:powershell can not click click a buttonpowershell无法点击点击按钮
【发布时间】:2019-12-22 07:46:47
【问题描述】:

这是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>

任何建议都请

【问题讨论】:

标签: windows powershell


【解决方案1】:

当然,您可以使用 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 

当然,这些暂停并不总是必要的,但我将它们留在那里只是为了延迟查看正在发生的事情并确保在采取下一个操作之前渲染已经完成

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-08
    • 2011-07-14
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    • 2020-05-05
    相关资源
    最近更新 更多