Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Selenium setting SelectItem

    I am developing test in selenium IDE using the user-extensions.js as described here: http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/docs/UsingSelenium.html

    It seems to work great, except I can't seem to figure out how to set the value of a SelectItem from Selenium.

    This is just a general question on how this is done, so any help would be appreciated.

    --------------------------
    http://forecast.it - Estimate · Execute · Deliver

    #2
    Solution

    Ok, so I managed to get this working, but it is not a pretty solution.

    If others have the same problem, I have included the code below. The generel idea is that the field is first clicked and then some keypresses of the first letter is used to select the correct value.

    Any alternative methods are appreciated, but this seems to do the trick for me.

    Code:
    	public void SetSelectedValueSelectItem(String locator, String itemText){
    		
    		selenium.click(locator);
    		
    		boolean nameFound = false;
    		int counter = 0;
    		while (!nameFound){
    			selenium.keyPress(locator, itemText.substring(0, 1));
    			String typeSelected = selenium.getText(locator);
    			
    			nameFound = typeSelected.toLowerCase().equals(itemText.toLowerCase());
    			
    			counter++;
    			
    			if (!nameFound && counter == 20){
    				fail("cannot select " + itemText + " in select item with scLocator " + locator);
    			}
    		}	
    	}
    --------------------------
    http://forecast.it - Estimate · Execute · Deliver

    Comment


      #3
      I am doing this slightly different (but not necessarily better):
      -Click the picker (the ScLocator with /[icon='picker'])
      -Search the list for the text (the ScLocators with /pickList) and click the matching cell

      I cannot provide concise code, because I have built a library upon Selenium 2 that encapsulates "mini-workflows" like this one and reuses code for similar elements, e.g. the picklist, which is like a grid.

      Comment

      Working...
      X