From c4130b76b52fa72985f0e20f53b4e9ae38664d16 Mon Sep 17 00:00:00 2001 From: Tomasz Zabkowicz Date: Fri, 4 Feb 2011 15:21:37 +0000 Subject: [PATCH] Implemented setColorPicker method in WebClientUtils --- src/main/java/pl/labno/bernard/htmlunified/WebClientUtils.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+), 0 deletions(-) diff --git a/src/main/java/pl/labno/bernard/htmlunified/WebClientUtils.java b/src/main/java/pl/labno/bernard/htmlunified/WebClientUtils.java index b65af72..000bcbc 100644 --- a/src/main/java/pl/labno/bernard/htmlunified/WebClientUtils.java +++ b/src/main/java/pl/labno/bernard/htmlunified/WebClientUtils.java @@ -4,9 +4,11 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.DomNodeList; import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlTableCell; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -128,4 +130,20 @@ public class WebClientUtils { } } } + + public static void setColorPickerValue(WebClient webClient, HtmlElement colorPicker, String hex) throws IOException { + HtmlPage page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); + colorPicker.click(); + ((HtmlInput) page.getElementById(colorPicker.getId() + "-colorPicker-hex")).setValueAttribute(hex); + page.getElementById(colorPicker.getId() + "-colorPicker-popup").getHtmlElementsByTagName("button").get(0).click(); + } + + public static void setColorPickerValue(WebClient webClient, HtmlElement colorPicker, int red, int green, int blue) throws IOException { + HtmlPage page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); + colorPicker.click(); + ((HtmlInput) page.getElementById(colorPicker.getId() + "-colorPicker-rgb-r")).setValueAttribute(Integer.toString(red)); + ((HtmlInput) page.getElementById(colorPicker.getId() + "-colorPicker-rgb-g")).setValueAttribute(Integer.toString(green)); + ((HtmlInput) page.getElementById(colorPicker.getId() + "-colorPicker-rgb-b")).setValueAttribute(Integer.toString(blue)); + page.getElementById(colorPicker.getId() + "-colorPicker-popup").getHtmlElementsByTagName("button").get(0).click(); + } } -- libgit2 0.24.0