{"id":754,"date":"2023-02-26T16:06:12","date_gmt":"2023-02-26T08:06:12","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=754"},"modified":"2023-04-29T17:00:54","modified_gmt":"2023-04-29T09:00:54","slug":"python-selenium-mouse-events","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/python-selenium-mouse-events\/","title":{"rendered":"Python Selenium\u9f20\u6807\u4e8b\u4ef6"},"content":{"rendered":"<p>\u5728 WebDriver \u4e2d\uff0c\u5c06\u8fd9\u4e9b\u5173\u4e8e\u9f20\u6807\u64cd\u4f5c\u7684\u65b9\u6cd5\u5c01\u88c5\u5728 ActionChains \u7c7b\u63d0\u4f9b\uff1a<\/p>\n<ul>\n<li>perform()\uff1a\u6267\u884c\u6240\u6709 ActionChains \u4e2d\u5b58\u50a8\u7684\u884c\u4e3a<\/li>\n<li>context_click()\uff1a\u53f3\u51fb<\/li>\n<li>double_click()\uff1a\u53cc\u51fb<\/li>\n<li>drag_and_drop()\uff1a\u62d6\u52a8<\/li>\n<li>move_to_element()\uff1a\u9f20\u6807\u60ac\u505c<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\">from selenium import webdriver\n# \u5f15\u5165 ActionChains \u7c7b\nfrom selenium.webdriver.common.action_chains import ActionChains\n\ndriver = webdriver.Chrome()\ndriver.get(&quot;https:\/\/www.baidu.cn&quot;)\n\n# \u5b9a\u4f4d\u5230\u8981\u60ac\u505c\u7684\u5143\u7d20\nabove = driver.find_element_by_link_text(&quot;\u8bbe\u7f6e&quot;)\n# \u5bf9\u5b9a\u4f4d\u5230\u7684\u5143\u7d20\u6267\u884c\u9f20\u6807\u60ac\u505c\u64cd\u4f5c\nActionChains(driver).move_to_element(above).perform()\n\n\u2026\u2026<\/code><\/pre>\n<ul>\n<li><code>from selenium.webdriver import ActionChains<\/code><\/li>\n<\/ul>\n<p>\u5bfc\u5165\u63d0\u4f9b\u9f20\u6807\u64cd\u4f5c\u7684 ActionChains \u7c7b\u3002<\/p>\n<ul>\n<li><code>ActionChains(driver)<\/code><\/li>\n<\/ul>\n<p>\u8c03\u7528 ActionChains()\u7c7b\uff0c\u5c06\u6d4f\u89c8\u5668\u9a71\u52a8 driver \u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\u3002<\/p>\n<ul>\n<li><code>move_to_element(above)<\/code><\/li>\n<\/ul>\n<p>context_click()\u65b9\u6cd5\u7528\u4e8e\u6a21\u62df\u9f20\u6807\u53f3\u952e\u64cd\u4f5c\uff0c\u5728\u8c03\u7528\u65f6\u9700\u8981\u6307\u5b9a\u5143\u7d20\u5b9a\u4f4d\u3002<\/p>\n<ul>\n<li><code>perform()<\/code><\/li>\n<\/ul>\n<p>\u6267\u884c\u6240\u6709 ActionChains \u4e2d\u5b58\u50a8\u7684\u884c\u4e3a\uff0c\u53ef\u4ee5\u7406\u89e3\u6210\u662f\u5bf9\u6574\u4e2a\u64cd\u4f5c\u7684\u63d0\u4ea4\u52a8\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 WebDriver \u4e2d\uff0c\u5c06\u8fd9\u4e9b\u5173\u4e8e\u9f20\u6807\u64cd\u4f5c\u7684\u65b9\u6cd5\u5c01\u88c5\u5728 ActionChains \u7c7b\u63d0\u4f9b\uff1a perform [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221],"tags":[],"class_list":["post-754","post","type-post","status-publish","format-standard","hentry","category-selenium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=754"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/754\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}