Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendMouseWheelEvent does not work on subsequent page loads - short repro attached #649

Open
Neori12 opened this issue Sep 11, 2022 · 0 comments

Comments

@Neori12
Copy link

Neori12 commented Sep 11, 2022

I had been having an issue with SendMouseWheelEvent, which does not seem to work in subsequent page loads (unless the browser is interferred with actual mouse scroll).
Below is a short reproducible python script.
"errorrep" is the name of the python script. Please set the script name to be "errorrep.py" as I'm using the script filename itself in certain lines of code.
Thank you so much for any aid in sorting this out!

"""
SendMouseWheelEvent is correctly performed on the first page load. On any pageloads after that, it does not seem to work, but it works again when the actual mouse device performs a scroll on the webpage

'# test 1' which does a javascript code 'scrollBy', works on every pageload.
'# test 2' which does a SendMouseWheelEvent, only works on first page load.

"""

from cefpython3 import cefpython as cef
import time
from threading import Thread
import errorrep

mybrowser = None

def main():
    cef.Initialize()
    browser = cef.CreateBrowserSync(url="https://stackoverflow.com/")
    browser.SetClientHandler(LoadHandler())
    errorrep.mybrowser = browser
    cef.MessageLoop()
    del browser
    cef.Shutdown()


class LoadHandler(object):
    def OnLoadingStateChange(self, browser, is_loading, **_):
        if not is_loading:
            Thread(target=test).start()


def test():
  print("Page loading is complete!")
  for i in range(5):
    print('scrolling')
    # test 1
    errorrep.mybrowser.ExecuteJavascript(jsCode="""scrollBy(0,25)""")
    # test 2
    # errorrep.mybrowser.SendMouseWheelEvent(0,0,0,-120, cef.EVENTFLAG_NONE)
    time.sleep(1)
  print('opening new page, clicking on the logo link')
  errorrep.mybrowser.ExecuteJavascript(jsCode="""document.getElementsByClassName('s-topbar--logo js-gps-track')[0].click();""")


if __name__ == '__main__':
    main()

cefpython version is 66.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant