{"id":1476,"date":"2015-04-28T15:11:09","date_gmt":"2015-04-28T07:11:09","guid":{"rendered":"http:\/\/www.qa-knowhow.com\/?p=1476"},"modified":"2015-04-28T15:11:09","modified_gmt":"2015-04-28T07:11:09","slug":"%e5%ae%89%e8%a3%9d%e4%b8%a6%e5%ae%8c%e6%88%90%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e5%80%8b-seleniumjava-%e6%b8%ac%e8%a9%a6%e7%a8%8b%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.qa-knowhow.com\/?p=1476","title":{"rendered":"\u5b89\u88dd\u4e26\u5b8c\u6210\u4f60\u7684\u7b2c\u4e00\u500b Selenium\/Java \u6e2c\u8a66\u7a0b\u5f0f"},"content":{"rendered":"<h2>\u5b89\u88dd\u4e26\u5b8c\u6210\u4f60\u7684\u7b2c\u4e00\u500b Selenium\/Java \u6e2c\u8a66\u7a0b\u5f0f<\/h2>\n<p>\u9019\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7d39\u5982\u4f55\u6e96\u5099\u4e00\u500b selenium\u7684\u958b\u767c\u74b0\u5883\uff0c\u4ee5 Java \u70ba\u4f8b\u5b50\u3002<\/p>\n<p>\u4e26\u4e14\u7c21\u55ae\u7684\u6a21\u64ec\u4e00\u500b\u7528 fireFox \u5230google Search \u7684\u700f\u89bd\u884c\u70ba\u3002<\/p>\n<h2>Step 1 : \u5b89\u88dd JDK<\/h2>\n<p>\u9996\u5148\u5fc5\u9808\u5b89\u88dd\uff0cJDK\uff0c\u53ef\u5230\u4e0b\u5217\u7db2\u5740\u5b89\u88dd<\/p>\n<p><a title=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html\" href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html\">http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Step 2: \u5b89\u88dd Java Editor<\/h2>\n<p>\u5b89\u88dd Java Editor \u4e3b\u8981\u7528\u5728\u958b\u767c Java \u7684\u7a0b\u5f0f\u3002\u9019\u90e8\u5206\u53ef\u4ee5\u4f9d\u7167\u500b\u4eba\u7684\u4f7f\u7528\u7fd2\u6163\u800c\u5b9a\u3002<\/p>\n<p>\u9019\u500b\u4f8b\u5b50\u6211\u5011\u9078\u64c7\u5b89\u88ddEclipse IDE\u3002<a title=\"http:\/\/www.eclipse.org\/downloads\" href=\"http:\/\/www.eclipse.org\/downloads\">http:\/\/www.eclipse.org\/downloads<\/a><\/p>\n<p>\u4e0b\u8f09\u5b8c\u5f8c\uff0c\u89e3\u58d3\u7e2e\u57f7\u884c &#8221;\u00a0<strong>eclipse.exe&#8221;<\/strong><\/p>\n<h2>Step 3: \u4e0b\u8f09 Java WebDriver<\/h2>\n<p>\u9019\u500b\u90e8\u5206\u4e3b\u8981\u4e0b\u8f09 Selenium WebDriver \u5c0d\u65bc\u7a0b\u5f0f\u8a9e\u8a00\u7684\u5957\u4ef6\u3002<\/p>\n<p>\u6bcf\u500b\u7a0b\u5f0f\u8a9e\u8a00\u90fd\u6703\u6709\u76f8\u5c0d\u61c9\u7684\u5957\u4ef6\u3002\u53ef\u53c3\u8003\u5982\u4e0b\u3002\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u4e3b\u8981\u4e0b\u8f09\u7684\u662f Java \u7684 Webdriver \u5957\u4ef6\u3002<\/p>\n<p>\u89e3\u58d3\u7e2e\u4e4b\u5f8c\u6703\u6709\u8a31\u591a\u76f8\u5c0d\u61c9\u7684 JAR \u6a94\u6848<\/p>\n<table>\n<tbody>\n<tr>\n<td><a href=\"http:\/\/selenium-release.storage.googleapis.com\/2.45\/selenium-java-2.45.0.zip\">Download<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a title=\"http:\/\/docs.seleniumhq.org\/download\" href=\"http:\/\/docs.seleniumhq.org\/download\">http:\/\/docs.seleniumhq.org\/download<\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.toolsqa.com\/wp-content\/uploads\/2014\/02\/Download-Webdriver-Java-Client-1.png\" alt=\"Download-Webdriver-Java-Client-1\" \/><\/p>\n<h2>Step 4: \u8a2d\u5b9a E<strong>clipse<\/strong><\/h2>\n<p>\u5c07\u6b65\u9a5f3\uff0c\u6240\u89e3\u58d3\u7e2e\u7684 Selenium JAR \u6a94\u6848\uff0c\u5168\u90e8\u8a2d\u5b9a\u5230 Eclipse \u4e2d\u3002\u5305\u542b\u6839\u76ee\u9304\u8207\\libs\\\u76ee\u9304\u4e0b\u6240\u6709\u7684 Jar \u6a94\u6848<\/p>\n<p>Right click on Project Name &gt;\u00a0<strong>Select Properties<\/strong> &gt; <strong>Java build path<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"http:\/\/www.toolsqa.com\/wp-content\/uploads\/2014\/02\/Selenium-Jar-1.png\" alt=\"Selenium-Jar-1\" width=\"602\" height=\"459\" \/><\/p>\n<h2>Step 5: \u64b0\u5beb\u7b2c\u4e00\u500b Selenium \/Java \u7a0b\u5f0f<\/h2>\n<p>[pastacode lang=&#8221;java&#8221; message=&#8221;Google Search Selenium Sample&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;]<\/p>\n<pre><code> \r\nimport org.openqa.selenium.*;\r\nimport org.openqa.selenium.firefox.FirefoxDriver;\r\n\r\npublic class FirstTestCase {\r\n \r\n    private static WebDriver driver = null;\r\n \r\n    public static void main(String[] args) {\r\n \r\n        \/\/ Launch FireFox browser\r\n         driver = new FirefoxDriver();\r\n \r\n        \/\/Implicit wait - 10 sec \r\n        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);\r\n \r\n        \/\/Visit www.google.com \r\n        driver.get(&#34;https:\/\/www.google.com&#34;);\r\n \r\n\r\n        \/\/ Locate the search input box and input &#34;Testing Search&#34;\r\n         driver.findElement(By.xpath(&#34;.\/\/*[@id=&#039;lst-ib&#039;]&#34;)).sendKeys(&#34;Testing Search &#34;);\r\n \r\n \r\n \r\n        \/\/ Close the browser\r\n         driver.quit();\r\n \r\n            }\r\n \r\n    }<\/code><\/pre>\n<p>[\/pastacode]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>That&#8217;s all. \u900f\u904e Selenium WebDriver \u7a0b\u5f0f\u8a9e\u8a00 (Java, Python, C#\u7b49)\uff0c\u5c31\u53ef\u4ee5\u6a21\u64ec\u4f7f\u7528\u8005\u8f38\u5165\u8207\u700f\u89bd\u5668\u6e9d\u901a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88dd\u4e26\u5b8c\u6210\u4f60\u7684\u7b2c\u4e00\u500b Selenium\/Java \u6e2c\u8a66\u7a0b\u5f0f \u9019\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7d39\u5982\u4f55\u6e96\u5099\u4e00\u500b selenium\u7684\u958b\u767c\u74b0\u5883\uff0c\u4ee5 Java \u70ba\u4f8b\u5b50\u3002 \u4e26\u4e14\u7c21\u55ae\u7684\u6a21\u64ec\u4e00\u500b\u7528 fireFox \u5230google Search \u7684\u700f\u89bd\u884c\u70ba\u3002 Step 1 : \u5b89\u88dd JDK \u9996\u5148\u5fc5\u9808\u5b89\u88dd\uff0cJDK\uff0c\u53ef\u5230\u4e0b\u5217\u7db2\u5740\u5b89\u88dd http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html &nbsp; Step 2: \u5b89\u88dd Java Editor \u5b89\u88dd Java Editor \u4e3b\u8981\u7528\u5728\u958b\u767c Java \u7684\u7a0b\u5f0f\u3002\u9019\u90e8\u5206\u53ef\u4ee5\u4f9d\u7167\u500b\u4eba\u7684\u4f7f\u7528\u7fd2\u6163\u800c\u5b9a\u3002 \u9019\u500b\u4f8b\u5b50\u6211\u5011\u9078\u64c7\u5b89\u88ddEclipse IDE\u3002http:\/\/www.eclipse.org\/downloads \u4e0b\u8f09\u5b8c\u5f8c\uff0c\u89e3\u58d3\u7e2e\u57f7\u884c &#8221;\u00a0eclipse.exe&#8221; Step 3: \u4e0b\u8f09 Java WebDriver \u9019\u500b\u90e8\u5206\u4e3b\u8981\u4e0b\u8f09 Selenium WebDriver \u5c0d\u65bc\u7a0b\u5f0f\u8a9e\u8a00\u7684\u5957\u4ef6\u3002 \u6bcf\u500b\u7a0b\u5f0f\u8a9e\u8a00\u90fd\u6703\u6709\u76f8\u5c0d\u61c9\u7684\u5957\u4ef6\u3002\u53ef\u53c3\u8003\u5982\u4e0b\u3002\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u4e3b\u8981\u4e0b\u8f09\u7684\u662f Java \u7684 Webdriver \u5957\u4ef6\u3002 \u89e3\u58d3\u7e2e\u4e4b\u5f8c\u6703\u6709\u8a31\u591a\u76f8\u5c0d\u61c9\u7684 JAR \u6a94\u6848 Download http:\/\/docs.seleniumhq.org\/download Step [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"categories":[80,51],"tags":[91,58],"_links":{"self":[{"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=\/wp\/v2\/posts\/1476"}],"collection":[{"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1476"}],"version-history":[{"count":1,"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=\/wp\/v2\/posts\/1476\/revisions"}],"predecessor-version":[{"id":1477,"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=\/wp\/v2\/posts\/1476\/revisions\/1477"}],"wp:attachment":[{"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qa-knowhow.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}