xlmaster
xlmaster

Reputation: 721

VBA selenium scroll windows to element point

In VBA I need to move in Selenium viewport to the element to be clickable. I tried code below ;

.Mouse.MoveTo(.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a"),13,13) 'error Expeted = sign
.Actions.MoveToElement (.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a")) 'ineffective screen does not scroll down. Note: Windos is set to Maximize

the code is added but does not work, I could not add to the comment section

.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a").Click
.Actions.MoveToElement(.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
.Actions.MoveToElement(.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
.Actions.MoveByOffset(300, 300).Perform
.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a").Click

Upvotes: 1

Views: 1373

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193168

To move Selenium's focus to the element you can use either of the following lines of code:

.Actions.MoveToElement(.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform

or

.Actions.MoveToElement(.FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a"), 13, 13).Perform

Upvotes: 1

Related Questions