简体   繁体   English

powershell无法点击点击按钮

[英]powershell can not click click a button

Here is the PS code这是PS代码

$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这是 HTML 代码

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

any suggesting please任何建议请

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.当然,您可以使用 Powershell 单击网页上的内容,但您必须使用目标元素和方法明确告诉它。

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)当然,这些暂停并不总是必要的,但我将它们放在那里只是为了延迟查看正在发生的事情并确保在采取下一步行动之前渲染已经完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM