-
-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Perform mouse clicks and mouse movements programmatically. | ||
|
||
from cefpython3 import cefpython as cef | ||
|
||
|
||
def main(): | ||
cef.Initialize() | ||
browser = cef.CreateBrowserSync( | ||
url="data:text/html,<h1>Mouse clicks snippet</h1>" | ||
"This text will be selected after one second.<br>" | ||
"This text will be selected after two seconds.", | ||
window_title="Mouse clicks") | ||
browser.SetClientHandler(LifespanHandler()) | ||
cef.MessageLoop() | ||
del browser | ||
cef.Shutdown() | ||
|
||
|
||
def click_after_1_second(browser): | ||
print("Click after 1 second") | ||
browser.SendMouseMoveEvent(0, 70, False, 0) | ||
browser.SendMouseClickEvent(0, 70, cef.MOUSEBUTTON_LEFT, False, 1) | ||
browser.SendMouseMoveEvent(400, 80, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) | ||
browser.SendMouseClickEvent(400, 80, cef.MOUSEBUTTON_LEFT, True, 1) | ||
cef.PostDelayedTask(cef.TID_UI, 1000, click_after_2_seconds, browser) | ||
|
||
|
||
def click_after_2_seconds(browser): | ||
print("Click after 2 seconds") | ||
browser.SendMouseMoveEvent(0, 90, False, 0) | ||
browser.SendMouseClickEvent(0, 90, cef.MOUSEBUTTON_LEFT, False, 1) | ||
browser.SendMouseMoveEvent(400, 100, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) | ||
browser.SendMouseClickEvent(400, 100, cef.MOUSEBUTTON_LEFT, True, 1) | ||
cef.PostDelayedTask(cef.TID_UI, 1000, click_after_1_second, browser) | ||
|
||
|
||
class LifespanHandler(object): | ||
def OnLoadEnd(self, browser, **_): | ||
# Execute function with a delay of 1 second after page | ||
# has completed loading. | ||
print("Page completed loading") | ||
cef.PostDelayedTask(cef.TID_UI, 1000, click_after_1_second, browser) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters