首页 > 解决方案 > 带有 Selenium 的 Powershell:我无法让“滚动视图”工作

问题描述

我需要向下滚动页面到NEXT按钮。只有NEXT按钮可见才能点击。所以我需要让滚动进入视图才能工作。

$browser = Start-SeChrome
$browser.Navigate().GoToURL($url)

ForEach ($A_Element in (Find-SeElement -Driver $browser -TagName a))      
   { 
    If ($A_Element.Text -Notlike "Next"){Conitnue} 
    $A_Element.ScrollIntoView()
    #Invoke-SeClick -Element $A_Element       
    #$A_Element.Click() 
    sleep 2
    Break         
   }

标签: powershellselenium

解决方案


根据您网页的设计方式,您可以尝试通过以下方式在 PowerShell 代码中执行 JavaScript 代码:

$browser.ExecuteScript("javascript code goes here").

您可以尝试以下方法:

$browser.ExecuteScript("document.scrollTo($($A_Element.Location.X),$($A_Element.Location.Y))")

推荐阅读