Search code examples
vbaseleniumscrollvisible

vba selenium if element not visible on screen codes are not working


I would ask you a question. I just now figured out this. In vba selenium if a website loaded fully but you cant see whole site so you need to scroll down to see whole site. vba is applying code if you cant see that class ,id or whatever parameter you are using in your code until you see that thing on your window. let me explain more clear.

i opened a website with vba selenium chromedriver. vba should click a button after filling up form. if after website fully loaded and button is not visible at first site loaded and i need to scroll down to see the button, button.click will not work. if i scroll down and see button and then only button.click will work.

if i change zoom with

driver.ExecuteScript "document.body.style.zoom='50%';"

then not any click command is working.

anybody has any idea how to do that?

the thing im trying to do; when site loaded captcha is coming. and im giving to user 10 sec to solve captcha. and then automate will click login. if i scroll down to see login button its fine working. if i dont scroll down to see login button code it not working.

next pages im taking from site all links which i want to click with this code;

For Each site In sites
Debug.Print site.Attribute("href")
site.Click ("href")
sayfa.Wait 10000
sayfa.SwitchToNextWindow
sayfa.Window.Close
sayfa.SwitchToPreviousWindow
Next site

it was always giving error. finally i figured out it. if i can see on website without scroll down or up that link which i will click, its working. but if i cant see link code is not working.

i became crazy :)

i will be appreciate if anybody can help.


Solution

  • solved. i added

    Site.ScrollIntoView True

    If Site.IsDisplayed Then
    driver.Wait 10000
    Site.ScrollIntoView True
    Site.Click ("href")
    driver.Wait 20000
    driver.SwitchToNextWindow
    driver.Window.Close
    driver.SwitchToPreviousWindow
    Else
    End If
    
    Next Adres