{"id":2360,"date":"2012-12-15T11:21:23","date_gmt":"2012-12-15T03:21:23","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=2360"},"modified":"2012-12-16T01:28:45","modified_gmt":"2012-12-15T17:28:45","slug":"web%e8%87%aa%e5%8a%a8%e5%8c%96%e6%b5%8b%e8%af%95%e5%b7%a5%e5%85%b7selenium","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/2360.html","title":{"rendered":"web\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177selenium"},"content":{"rendered":"<p><span style=\"font-size: small; color: #ff0000;\">Selenium \u4ecb\u7ecd<\/span><\/p>\n<p><span style=\"font-size: small;\">Selenium\u4e5f\u662f\u4e00\u4e2a\u7528\u4e8eWeb\u5e94\u7528\u7a0b\u5e8f\u6d4b\u8bd5\u7684\u5de5\u5177\u3002Selenium \u6d4b\u8bd5\u76f4\u63a5\u8fd0\u884c\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u5c31\u50cf\u771f\u6b63\u7684\u7528\u6237\u5728\u64cd\u4f5c\u4e00\u6837\u3002\u652f\u6301\u7684\u6d4f\u89c8\u5668\u5305\u62ecIE,Mozilla\u548cFirefox\u7b49\u3002\u8fd9\u4e2a\u5de5\u5177\u7684\u4e3b\u8981\u529f\u80fd\u5305\u62ec\uff1a\u6d4b\u8bd5\u4e0e\u6d4f\u89c8\u5668\u7684\u517c\u5bb9\u6027&#8211;\u6d4b\u8bd5\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u770b\u662f\u5426\u80fd\u591f\u5f88\u597d\u5f97\u5de5\u4f5c\u5728\u4e0d\u540c\u6d4f\u89c8\u5668\u548c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u4e0a\u3002\u6d4b\u8bd5\u7cfb\u7edf\u529f\u80fd&#8211;\u521b\u5efa\u8870\u9000\u6d4b\u8bd5\u68c0\u9a8c\u8f6f\u4ef6\u529f\u80fd\u548c\u7528\u6237\u9700\u6c42\u3002 \u652f\u6301\u81ea\u52a8\u5f55\u5236\u52a8\u4f5c\uff0c\u548c\u81ea\u52a8\u751f\u6210\u3002Net\u3001Java\u3001Perl\u7b49\u4e0d\u540c\u8bed\u8a00\u7684\u6d4b\u8bd5\u811a\u672c\u3002Selenium \u662f ThoughtWorks \u4e13\u95e8\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u7f16\u5199\u7684\u4e00\u4e2a\u9a8c\u6536\u6d4b\u8bd5\u5de5\u5177\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">Selenium \u7684\u7ec4\u6210\uff1a<\/span><\/p>\n<p><span style=\"font-size: small;\">Selenium IDE\uff1afirefox \u7684 plug-in\u3002 \u662f\u6d4f\u89c8\u5668\u7684\u5de5\u5177\uff0c\u4e0d\u80fd\u5b89\u88c5\u5728IE\u4e0a\u3002<\/span><br \/>\n<span style=\"font-size: small;\"> Selenium Core:\u7eaf\u7cb9\u7531Javascr\u012bpt\u7ec4\u6210\u7684\uff0c\u6709assertion\u673a\u5236\u7684test suit runnner.<\/span><br \/>\n<span style=\"font-size: small;\"> Selenium Remote Control:\u4e00\u4e2a\u4ee3\u7406\u4e0e\u63a7\u5236\u7aef\uff0c \u53ef\u4ee3\u66ffSelenium core \u548cIDE \u7684client\u7aef\u3002(\u76f8\u5f53\u4e8e\u901a\u8fc7\u7f16\u7a0b\u6765\u5b9e\u73b0\u4e00\u5207)\uff0c\u662f\u652f\u6301\u591a\u8bed\u8a00\u7684.<\/span><\/p>\n<p><span style=\"font-size: small;\">\u4e0b\u8f7dfirefox\u7684IDE\u63d2\u4ef6\uff0chttp:\/\/seleniumhq.org\/download\/\uff0c\u4e0b\u8f7d\u540e\u6253\u5f00ff\uff0c\u5de5\u5177-&gt;\u9644\u52a0\u7ec4\u4ef6-&gt;\u4ece\u6587\u4ef6\u5b89\u88c5\u9644\u52a0\u7ec4\u4ef6\uff0c\u5b89\u88c5\u6211\u4eec\u4e0b\u8f7d\u7684Selenium IDE\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u5b89\u88c5\u597d\u6253\u5f00\u540e\u5982\u56fe\uff1a<\/span><\/p>\n<p><a href=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/12\/1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2361\" title=\"1\" src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/12\/1.png\" alt=\"\" width=\"713\" height=\"549\" srcset=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/12\/1.png 713w, https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/12\/1-300x230.png 300w, https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/12\/1-194x150.png 194w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/a><\/p>\n<p><span style=\"font-size: small; color: #ff0000;\">\u7528python\u5199\u6d4b\u8bd5\u7528\u4f8b<\/span><\/p>\n<p><span style=\"font-size: small;\">\u8fd9\u91cc\u4e3b\u8981\u7528\u5230Selenium WebDriver\u6765\u7f16\u7a0b\uff0c\u5b9e\u73b0\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002\u524d\u9762\u5b89\u88c5\u7684IDE\uff0c\u5f55\u5236\u597d\u52a8\u4f5c\u4e4b\u540e\uff0c\u4e5f\u53ef\u4ee5\u5c06\u5176\u5bfc\u51fa\u4e3a\u5404\u79cd\u8bed\u8a00\u7684\u811a\u672c\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u9996\u5148\u5b89\u88c5python\u7684selenium\u5e93\u3002<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo pip install selenium\r\n<\/pre>\n<p><span style=\"font-size: small;\">\u4e0b\u9762\u662f\u6211\u5199\u7684\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b\uff0c\u4e3b\u8981\u5c31\u662f\u767b\u9646\u7f51\u7ad9\uff0c\u53d1\u5e03\u4e00\u6761\u56fe\u7247\u72b6\u6001\uff0c\u7b49\u3002<\/span><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#encoding=utf-8\r\nfrom selenium import webdriver\r\nfrom selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0\r\nfrom time import sleep\r\nfrom os import getcwd\r\n\r\nHOST='http:\/\/moxian.com'\r\nUSER_EMAIL = 'xxx@qq.com'\r\nUSER_PASS = 'xxx'\r\n#driver = webdriver.Chrome('.\/chromedriver')\r\ndriver = webdriver.Firefox()\r\n\r\ndriver.get(HOST)\r\n\r\ninputElement = driver.find_element_by_id(&quot;txtEmailUser&quot;)\r\n\r\ninputElement.send_keys(USER_EMAIL)\r\ndriver.find_element_by_id(&quot;txtEmailPwd&quot;).send_keys(USER_PASS)\r\ninputElement.submit()\r\n\r\ntry:\r\n    WebDriverWait(driver, timeout=10).until(lambda driver: driver.find_element_by_id(&quot;moxin_msg_input&quot;))\r\n    #\u53d1\u4e00\u6761\u9690\u79c1\u56fe\u7247\u9b54\u4fe1\r\n    driver.find_element_by_id('msg_pic_btn').click()\r\n    sleep(0.5)\r\n    driver.find_element_by_id('moxin_local_img').send_keys(getcwd()+'\/1.jpg')\r\n    driver.find_element_by_id('uploadForm').submit()\r\n    sleep(0.5)\r\n    WebDriverWait(driver, timeout=60).until(lambda driver: driver.find_element_by_id(&quot;upload_image&quot;))\r\n    driver.find_element_by_css_selector('textarea.moxin_msg_str').send_keys(u'\u81ea\u52a8\u53d1\u7684\u4e00\u6761\u6d4b\u8bd5\u9b54\u4fe1')\r\n    #\u8bbe\u7f6e\u9690\u79c1\r\n    driver.find_element_by_css_selector(&quot;div.msg_set_btn a.pngimg&quot;).click()\r\n    #xpath\u53ef\u4ee5\u901a\u8fc7chrome\uff0c\u5ba1\u67e5\u5143\u7d20\u5b9a\u4f4d\u540e\uff0c\u53f3\u952e\u590d\u5236xpath\u503c\r\n    driver.find_element_by_xpath(&quot;\/\/*&#x5B;@id='upload_forjs_content']\/div&#x5B;2]\/div&#x5B;3]\/div\/div&#x5B;2]\/div\/div&#x5B;2]\/ul\/li&#x5B;4]&quot;).click()\r\n    driver.find_element_by_class_name('msg_submit').click()\r\n    #\u559c\u6b22\u521a\u53d1\u7684\u90a3\u6761\u9b54\u4fe1\r\n    sleep(2)\r\n    driver.find_element_by_css_selector('span.mx-share-like').click()\r\n    #\u8bc4\u8bba\u9b54\u4fe1\r\n    driver.find_element_by_css_selector('span.mx-share-reply').click()\r\n    sleep(1)\r\n    driver.find_element_by_css_selector('.mx-moxin-reply-form textarea').send_keys(u'\u81ea\u52a8\u8bc4\u8bba')\r\n    driver.find_element_by_css_selector('.mx-moxin-reply-form .sendbtn').click()\r\nfinally:\r\n    #driver.quit()\r\n    pass\r\n<\/pre>\n<p><span style=\"font-size: small; color: #ff0000;\">\u6548\u679c\u6f14\u793a(\u9700\u8981\u652f\u6301html5\u7684\u6d4f\u89c8\u5668)\uff1a<\/span><\/p>\n<p><video width=\"864\" height=\"486\" controls=\"controls\"><source src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/12\/selenium-demo.mp4\" type=\"video\/mp4\" \/><object width=\"1366\" height=\"768\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"src\" value=\"https:\/\/kyle.ai\/blog\/wp-includes\/js\/tinymce\/plugins\/media\/moxieplayer.swf\" \/><param name=\"flashvars\" value=\"url=\/blog\/wp-content\/uploads\/2012\/12\/selenium-demo.mp4&amp;poster=\/blog\/wp-admin\/\" \/><param name=\"allowfullscreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"true\" \/><embed width=\"1366\" height=\"768\" type=\"application\/x-shockwave-flash\" src=\"https:\/\/kyle.ai\/blog\/wp-includes\/js\/tinymce\/plugins\/media\/moxieplayer.swf\" flashvars=\"url=\/blog\/wp-content\/uploads\/2012\/12\/selenium-demo.mp4&amp;poster=\/blog\/wp-admin\/\" allowfullscreen=\"true\" allowscriptaccess=\"true\" \/><\/object><\/video><\/p>\n<p><span style=\"font-size: small;\">\u8fd9\u53ea\u662f\u4e00\u4e9b\u5165\u95e8\u7ea7\u5e94\u7528\uff0c\u66f4\u591a\u9ad8\u7ea7\u7528\u6cd5\uff0c\u8fd8\u9700\u8981\u65f6\u95f4\u7ee7\u7eed\u5b66\u4e60\u4e86\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium \u4ecb\u7ecd Selenium\u4e5f\u662f\u4e00\u4e2a\u7528\u4e8eWeb\u5e94\u7528\u7a0b\u5e8f\u6d4b\u8bd5\u7684\u5de5\u5177\u3002Selenium \u6d4b\u8bd5\u76f4\u63a5\u8fd0\u884c\u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2360","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=2360"}],"version-history":[{"count":5,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2360\/revisions"}],"predecessor-version":[{"id":2366,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2360\/revisions\/2366"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=2360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=2360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=2360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}