1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import com.gargoylesoftware.htmlunit.ElementNotFoundException; 41 import com.gargoylesoftware.htmlunit.KeyValuePair; 42 import com.gargoylesoftware.htmlunit.Page; 43 import java.io.IOException ; 44 import java.util.Map ; 45 46 import org.apache.commons.lang.StringUtils; 47 48 57 public class HtmlImageInput extends HtmlInput { 58 59 private boolean wasPositionSpecified_ = false; 61 private int xPosition_; 62 private int yPosition_; 63 64 70 public HtmlImageInput( final HtmlPage page, final Map attributes ) { 71 super( page, attributes ); 72 } 73 74 75 84 public KeyValuePair[] getSubmitKeyValuePairs() { 85 final String name = getNameAttribute(); 86 final String prefix; 87 if (StringUtils.isEmpty(name)) { 89 prefix = ""; 90 } 91 else { 92 prefix = name + "."; 93 } 94 95 if( wasPositionSpecified_ ) { 96 return new KeyValuePair[]{ 97 new KeyValuePair(prefix + "x", String.valueOf(xPosition_)), 98 new KeyValuePair(prefix + "y", String.valueOf(yPosition_)) 99 }; 100 } 101 return new KeyValuePair[]{new KeyValuePair( getNameAttribute(), getValueAttribute() )}; 102 } 103 104 105 114 public Page click() throws IOException { 115 return click(0,0); 116 } 117 118 130 protected Page doClickAction(final Page defaultPage) throws IOException { 131 return getEnclosingFormOrDie().submit(this); 132 } 133 134 135 146 public Page click( final int x, final int y ) 147 throws 148 IOException , 149 ElementNotFoundException { 150 151 wasPositionSpecified_ = true; 152 xPosition_ = x; 153 yPosition_ = y; 154 return super.click(); 155 } 156 } 157 158 | Popular Tags |