Reputation: 355
I need to scroll down the page to the NEXT
button. Only the NEXT
button is visible can it clicked on. So I need to get the scroll into view to work.
$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
}
Upvotes: 1
Views: 1150
Reputation: 355
I encountered this same issue again while working on a different script and have a better solution this time. These lines can be executed from Powershell directly, which is basically a call to Javascript. Its a combination of the answer provided by @bluecrimson9001 (above) and https://www.javascripttutorial.net/javascript-dom/javascript-scrollintoview/
#----Scroll into view----
$browser.executeScript("
Ref_Element = arguments[0];
Ref_Element.scrollIntoView();
", $A_Element)
#----Scroll into view----
Upvotes: 0
Reputation: 38
Depending on how your webpage is designed, you can try to execute JavaScript code within your PowerShell code by trying this:
$browser.ExecuteScript("javascript code goes here").
You could try something like:
$browser.ExecuteScript("document.scrollTo($($A_Element.Location.X),$($A_Element.Location.Y))")
Upvotes: 2
Reputation: 2326
I afraid there is something called ScrollIntoView for powershell. However there are ways to scroll down. You can use either of below two methods :
To press down arrow 10 times:
[System.Windows.Forms.SendKeys]::SendWait({{DOWN 10}})
To Scroll to a particular location:
[int]$horizontalLoc=0
[int]$verticalLoc= 90
browser.Document.parentWindow.scroll($horizontalLoc,$verticalLoc)
Upvotes: 0
Reputation: 389
You can try executing the javascript code for scrolling:
document.scrollIntoView();
execute this js code on your element. In c# it looks like this:
((IJavaScriptExecutor)driver).ExecuteScript("document.querySelector(arguments[0]).scrollIntoView();", A_Element);
Upvotes: 0