@@ -107,7 +107,7 @@ public void clickLinkWithExactText(String linkText, int index) {
107107 }
108108
109109 public void clickLinkWithImage (String imageFileName , int index ) {
110- selenium .click ("xpath=//a[contains(img/@src,'" + imageFileName + "')]" );
110+ selenium .click ("xpath=//a[contains(img/@src,'" + imageFileName + "')][" + index + 1 + "] " );
111111 selenium .waitForPageToLoad (timeout );
112112 }
113113
@@ -118,7 +118,7 @@ public void clickLinkWithText(String linkText, int index) {
118118 }
119119
120120 public void clickRadioOption (String radioGroup , String radioOptionValue ) {
121- selenium .click ("xpath=" + formSelector () + "//input[@name='" + radioGroup + "' and @value='"
121+ selenium .click ("xpath=" + formSelector () + "//input[@type='radio' and @ name='" + radioGroup + "' and @value='"
122122 + radioOptionValue + "']" );
123123 }
124124
@@ -260,7 +260,7 @@ public boolean hasLinkWithExactText(String linkText, int index) {
260260
261261 public boolean hasLinkWithImage (String imageFileName , int index ) {
262262 return selenium .isElementPresent ("xpath=//a[contains(img/@src,'"
263- + imageFileName + "')]" );
263+ + imageFileName + "')][" + index + 1 + "] " );
264264 }
265265
266266 public boolean hasLinkWithText (String linkText , int index ) {
@@ -292,26 +292,32 @@ public boolean hasSelectOptionValue(String selectName, String optionValue) {
292292 }
293293
294294 public boolean hasSubmitButton () {
295+ String xpath1 = formSelector () + "//input[@type='submit' or @type='image']" ;
296+ String xpath2 = formSelector () + "//button[@type='submit']" ;
295297 return selenium
296- .isElementPresent ("xpath=" + formSelector () + "(//input[@type='submit' or @type='image']|//button[@type='submit'])" );
298+ .isElementPresent ("xpath=" + xpath1 + "|" + xpath2 );
297299 }
298300
299301 public boolean hasSubmitButton (String nameOrID , String value ) {
302+ String xpath1 = formSelector () + "//input[(@type='submit' or @type='image') and (@id='"
303+ + nameOrID + "' or @name='" + nameOrID
304+ + "') and @value='" + value + "']" ;
305+ String xpath2 = formSelector () + "//button[@type='submit' and (@id='"
306+ + nameOrID + "' or @name='" + nameOrID
307+ + "') and @value='" + value + "']" ;
300308 return selenium
301- .isElementPresent ("xpath=" + formSelector () + "(//input[(@type='submit' or @type='image') and (@id='"
302- + nameOrID + "' or @name='" + nameOrID
303- + "') and @value='" + value + "']|//button[@type='submit' and (@id='"
304- + nameOrID + "' or @name='" + nameOrID
305- + "') and @value='" + value + "'])" );
309+ .isElementPresent ("xpath=" + xpath1 + "|" + xpath2 );
306310 }
307311
308312 public boolean hasSubmitButton (String nameOrID ) {
313+ String xpath1 = formSelector () + "//input[(@type='submit' or @type='image') and (@id='"
314+ + nameOrID + "' or @name='" + nameOrID
315+ + "')]" ;
316+ String xpath2 = formSelector () + "//button[@type='submit' and (@id='"
317+ + nameOrID + "' or @name='" + nameOrID
318+ + "')]" ;
309319 return selenium
310- .isElementPresent ("xpath=" + formSelector () + "(//input[(@type='submit' or @type='image') and (@id='"
311- + nameOrID + "' or @name='" + nameOrID
312- + "')]|//button[@type='submit' and (@id='"
313- + nameOrID + "' or @name='" + nameOrID
314- + "')])" );
320+ .isElementPresent ("xpath=" + xpath1 + "|" + xpath2 );
315321 }
316322
317323 public boolean hasResetButton () {
@@ -385,36 +391,44 @@ public void setScriptingEnabled(boolean value) {
385391 }
386392
387393 public void setTextField (String inputName , String text ) {
388- selenium .type ("xpath=" + formSelector () + "(//input[@name='" +inputName +"' and (@type='text' or @type='password' or @type='file')]|//textarea[@name='" +inputName +"'])" , text );
394+ String xpath1 = formSelector () + "//input[@name='" +inputName +"' and (@type='text' or @type='password' or @type='file')]" ;
395+ String xpath2 = formSelector () + "//textarea[@name='" +inputName +"']" ;
396+ selenium .type ("xpath=" + xpath1 + "|" + xpath2 , text );
389397 }
390398
391399 public void setWorkingForm (String nameOrId , int index ) {
392400 if (nameOrId != null )
393- formIdent ="(@name='" +nameOrId +"' or @id='" +nameOrId +"') and position()=" +index ;
401+ formIdent ="(@name='" +nameOrId +"' or @id='" +nameOrId +"')][ position()=" +( index + 1 ) ;
394402 else
395403 formIdent =null ;
396404 }
397405
398406 public void submit () {
399- selenium .click ("xpath=" + formSelector () + "(//input[@type='submit' or @type='image']|//button[@type='submit'])" );
407+ String xpath1 = formSelector () + "//input[@type='submit' or @type='image']" ;
408+ String xpath2 = formSelector () + "//button[@type='submit']" ;
409+ selenium .click ("xpath=" + xpath1 + "|" + xpath2 );
400410 selenium .waitForPageToLoad (timeout );
401411 }
402412
403- public void submit (String buttonName , String buttonValue ) {
404- selenium .click ("xpath=" + formSelector () + "(//input[(@type='submit' or @type='image') and (@id='"
405- + buttonName + "' or @name='" + buttonName
406- + "') and @value='" + buttonValue + "']|//button[@type='submit' and (@id='"
407- + buttonName + "' or @name='" + buttonName
408- + "') and @value='" + buttonValue + "'])" );
413+ public void submit (String nameOrID , String value ) {
414+ String xpath1 = formSelector () + "//input[(@type='submit' or @type='image') and (@id='"
415+ + nameOrID + "' or @name='" + nameOrID
416+ + "') and @value='" + value + "']" ;
417+ String xpath2 = formSelector () + "//button[@type='submit' and (@id='"
418+ + nameOrID + "' or @name='" + nameOrID
419+ + "') and @value='" + value + "']" ;
420+ selenium .click ("xpath=" + xpath1 + "|" + xpath2 );
409421 selenium .waitForPageToLoad (timeout );
410422 }
411423
412- public void submit (String buttonName ) {
413- selenium .click ("xpath=" + formSelector () + "(//input[(@type='submit' or @type='image') and (@id='"
414- + buttonName + "' or @name='" + buttonName
415- + "')]|//button[@type='submit' and (@id='"
416- + buttonName + "' or @name='" + buttonName
417- + "')])" );
424+ public void submit (String nameOrID ) {
425+ String xpath1 = formSelector () + "//input[(@type='submit' or @type='image') and (@id='"
426+ + nameOrID + "' or @name='" + nameOrID
427+ + "')]" ;
428+ String xpath2 = formSelector () + "//button[@type='submit' and (@id='"
429+ + nameOrID + "' or @name='" + nameOrID
430+ + "')]" ;
431+ selenium .click ("xpath=" + xpath1 + "|" + xpath2 );
418432 selenium .waitForPageToLoad (timeout );
419433 }
420434
@@ -525,7 +539,22 @@ public URL getPageURL() {
525539 * @see net.sourceforge.jwebunit.api.ITestingEngine#getSelectedRadio(java.lang.String)
526540 */
527541 public String getSelectedRadio (String radioGroup ) {
528- throw new UnsupportedOperationException ("getSelectedRadio" );
542+ int count = 0 ;
543+ while (selenium .isElementPresent ("xpath=" + formSelector () + "//input[@type='radio' and @name='" +radioGroup +"'][" +(count +1 )+"]" )) {
544+ if ("on" .equals (selenium .getValue ("xpath=" + formSelector () + "//input[@type='radio' and @name='" +radioGroup +"'][" +(count +1 )+"]" ))) {
545+ return selenium .getAttribute ("xpath=" + formSelector () + "//input[@type='radio' and @name='" +radioGroup +"'][" +(count +1 )+"]@value" );
546+ }
547+ count ++;
548+ }
549+ return null ;
550+ }
551+
552+ protected int getRadioCount (String radioGroup ) {
553+ int count = 0 ;
554+ while (selenium .isElementPresent ("xpath=" + formSelector () + "//input[@type='radio' and @name='" +radioGroup +"'][" +(count +1 )+"]" )) {
555+ count ++;
556+ }
557+ return count ;
529558 }
530559
531560 /* (non-Javadoc)
@@ -558,8 +587,7 @@ public void setExpectedJavaScriptPrompt(JavascriptPrompt[] prompts) throws Expec
558587 * @see net.sourceforge.jwebunit.api.ITestingEngine#setWorkingForm(int)
559588 */
560589 public void setWorkingForm (int index ) {
561- // TODO Auto-generated method stub
562- throw new UnsupportedOperationException ("setWorkingForm" );
590+ formIdent ="position()=" +(index +1 );
563591 }
564592
565593}
0 commit comments