{"id":1724,"date":"2015-01-22T11:02:47","date_gmt":"2015-01-22T02:02:47","guid":{"rendered":"http:\/\/blog.rutake.com\/techmemo\/?p=1724"},"modified":"2015-01-22T11:05:42","modified_gmt":"2015-01-22T02:05:42","slug":"%e7%94%bb%e9%9d%a2%e3%83%86%e3%82%b9%e3%83%88%e3%81%ae%e8%87%aa%e5%8b%95%e5%8c%96%e3%81%abselenium-webdriver","status":"publish","type":"post","link":"https:\/\/blog.rutake.com\/techmemo\/2015\/01\/22\/%e7%94%bb%e9%9d%a2%e3%83%86%e3%82%b9%e3%83%88%e3%81%ae%e8%87%aa%e5%8b%95%e5%8c%96%e3%81%abselenium-webdriver\/","title":{"rendered":"\u753b\u9762\u30c6\u30b9\u30c8\u306e\u81ea\u52d5\u5316\u306bSelenium Webdriver"},"content":{"rendered":"<p>\u30c6\u30b9\u30c8\u306e\u81ea\u52d5\u5316\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u307e\u3067\u306f\u3067\u304d\u3066\u3082\u3001\u753b\u9762\u306e\u81ea\u52d5\u5316\u307e\u3067\u624b\u304c\u56de\u3063\u3066\u3044\u306a\u3044\u3053\u3068\u304c\u591a\u3044\u3060\u308d\u3046\u3002<\/p>\n<p>\u753b\u9762\u306e\u30c6\u30b9\u30c8\u81ea\u52d5\u5316\u3068\u3044\u3048\u3070Selenium\u304c\u6709\u540d\u3060\u304c\u3001\u3057\u3070\u3089\u304f\u89e6\u308c\u306a\u3044\u3046\u3061\u306b\u30d0\u30fc\u30b8\u30e7\u30f3\uff12\u306b\u306a\u3063\u3066\u304a\u308a\u3001\u9032\u5316\u3057\u3066\u3044\u305f\u3002<\/p>\n<p>WebDriver\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3068\u30d6\u30e9\u30a6\u30b6\u3092\u5916\u90e8\u304b\u3089\u64cd\u4f5c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3001\u4eba\u9593\u306e\u5b9f\u6a5f\u64cd\u4f5c\u306b\u8fd1\u3044\u6319\u52d5\u3067\u30c6\u30b9\u30c8\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u9069\u5f53\u306a\u753b\u9762\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u5185\u90e8\u306e\u8981\u7d20\u3092\u8868\u793a\u3055\u305b\u308b\u30b5\u30f3\u30d7\u30eb\u3002<br \/>\nID\u3067\u898b\u3064\u3051\u3089\u308c\u308c\u3070Xpath\u306f\u4e0d\u8981\u3002<\/p>\n<p>[java]<br \/>\nimport java.io.File;<br \/>\nimport java.util.List;<\/p>\n<p>import org.apache.commons.io.FileUtils;<br \/>\nimport org.openqa.selenium.By;<br \/>\nimport org.openqa.selenium.OutputType;<br \/>\nimport org.openqa.selenium.TakesScreenshot;<br \/>\nimport org.openqa.selenium.WebDriver;<br \/>\nimport org.openqa.selenium.WebElement;<br \/>\nimport org.openqa.selenium.firefox.FirefoxDriver;<br \/>\nimport org.openqa.selenium.support.ui.ExpectedConditions;<br \/>\nimport org.openqa.selenium.support.ui.Wait;<br \/>\nimport org.openqa.selenium.support.ui.WebDriverWait;<\/p>\n<p>public class SeleniuimTest {<\/p>\n<p>\tpublic static void main(String[] args) throws InterruptedException {<br \/>\n\t\tWebDriver driver = new FirefoxDriver();<br \/>\n\t\tdriver.get(&#8220;http:\/\/www.example.com\/&#8221;);<br \/>\n\t\t\/\/ 30\u79d2\u5f85\u3064\u8a2d\u5b9a<br \/>\n\t\tWait<WebDriver> wait = new WebDriverWait(driver, 30);<br \/>\n\t\t\/\/ sideMenu\u3068\u3044\u3046\u8981\u7d20\u304c\u30af\u30ea\u30c3\u30af\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u307e\u3067\u307e\u3064\uff08\u305f\u3060\u305730\u79d2\uff09<br \/>\n\t\tWebElement button = wait.until(ExpectedConditions<br \/>\n\t\t\t\t.elementToBeClickable(By.className(&#8220;sideMenu&#8221;)));<br \/>\n\t\t\/\/ firebug\u306expath\u3092\u305d\u306e\u307e\u307e\u3067\uff2f\uff2b<br \/>\n\t\tSystem.out.println(driver.findElement(By.xpath(&#8220;\/html\/body\/div\/div\/div[2]\/div[2]\/div[1]\/ul\/li[1]\/a&#8221;)).getText());<br \/>\n\t\t\/\/ \u8907\u6570\u51e6\u7406\u3059\u308b\u5834\u5408<br \/>\n\t\tList<WebElement> elements = driver.findElements(By.xpath(&#8220;\/html\/body\/div\/div\/div[2]\/div[2]\/div[1]\/ul\/li&#8221;));<br \/>\n\t\tfor (WebElement webElement : elements) {<br \/>\n\t\t\tSystem.out.println(webElement.getText());<br \/>\n\t\t}<br \/>\n\t\t\/\/\u3000\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3082\u53d6\u308c\u308b\u3002<br \/>\n\t\ttry {<br \/>\n\t\t\tFileUtils.copyFile(<br \/>\n\t\t\t\t\t((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE),<br \/>\n\t\t\t\t\tnew File(&#8220;d:\/screen.jpg&#8221;));<br \/>\n\t\t} catch (Exception e) {<br \/>\n\t\t}<br \/>\n\t\tThread.sleep(10000);<br \/>\n\t\tdriver.quit();<br \/>\n\t}<br \/>\n}<br \/>\n[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c6\u30b9\u30c8\u306e\u81ea\u52d5\u5316\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u307e\u3067\u306f\u3067\u304d\u3066\u3082\u3001\u753b\u9762\u306e\u81ea\u52d5\u5316\u307e\u3067\u624b\u304c\u56de &hellip; <a href=\"https:\/\/blog.rutake.com\/techmemo\/2015\/01\/22\/%e7%94%bb%e9%9d%a2%e3%83%86%e3%82%b9%e3%83%88%e3%81%ae%e8%87%aa%e5%8b%95%e5%8c%96%e3%81%abselenium-webdriver\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[296,295],"tags":[298,299,297],"_links":{"self":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts\/1724"}],"collection":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/comments?post=1724"}],"version-history":[{"count":2,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts\/1724\/revisions"}],"predecessor-version":[{"id":1726,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts\/1724\/revisions\/1726"}],"wp:attachment":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/media?parent=1724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/categories?post=1724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/tags?post=1724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}