1

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
xlmaster
  • 659
  • 7
  • 23

1 Answers1

1

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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • first one without result, the second one gives an error 'Wrong number of element'. I changed to .Actions.MoveByOffset()..same result with same error – xlmaster Aug 21 '22 at 20:15
  • I tried to write similar java code from link you shared, but gives an error expected = sign. new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("element_cssSelector"))).click(); .WaitForScript(browser, .FindElementByXPath("//*[@id=""main-content""]/section[2]/ul/li[2]/div/a").Click,2000) – xlmaster Aug 21 '22 at 20:21
  • 1
    Java code won't suit VB environment. Let me check the code implementation. – undetected Selenium Aug 21 '22 at 21:53
  • I found somthing like below. It resolves partially. But I need, movetoelement Dim ks As Selenium.Keys Set ks = New Selenium.Keys .SendKeys ks.PageDown – xlmaster Aug 21 '22 at 22:45