-1

Is it possible to select value from the drop down list then you will get the value from the Array(parameter) data?

I tried to do it but I commit error. I also tried to get 'id'from the equivalent value of the list and it worked. I wonder if it's possible to select from string value(from array) VS string value(from drop down)

This is the sample screenshot of the code and the paramater of an array for the drop down. enter image description here

Hi,
Sorry for late reply. I forget to include the html source. This is what I used.

storeEval | Concern[storedVars.Myvar] | concern

click | id=ddlConcern 

echo | ${concern} 

select | name=ddlConcern |id=${concern}

The choices available on the drop down list (page) is actually on the stored array.But I cannot get the value (Drop down list(page) VS stored array )

  • Please: Show the code you have tried; explain VS; indicate which language you are using; give example of data. This will help us answer your question. – Michael Durrant Feb 3 '16 at 10:08
  • Hi, I add the sample screenshot for the code that I used and the array value. I used Selenium IDE only – user315583 Feb 3 '16 at 11:10
  • Hi Please share HTML code also so we can get your problem properly. – Sagar007 Feb 3 '16 at 12:25
2

There is no HTML code you are using and therefore we cannot evaluate what is going wrong here, but suspect this:

1) Read select command documentation:

select(selectLocator, optionLocator)

  • selectLocator - an element locator identifying a drop-down menu
  • optionLocator - an option locator (a label by default)

    • label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
    • value=valuePattern: matches options based on their values.
    • id=id: matches options based on their ids.
    • index=index: matches an option based on its index (offset from zero).

If no option locator prefix is provided, the default behaviour is to match on label.

Last sentence is most important. If you test according ID, your comand should look like:

select | id=dllConcern | id=${concern}

Consider tweaked example from W3C: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select

code:

<!DOCTYPE html>
<html>
<body>
<select id="cars">
   <option id="v" value="volvo">Volvo</option>
   <option id="s" value="saab">Saab</option>
   <option id="o" value="opel">Opel</option>
   <option id="a" value="audi">Audi</option>
</select>
</body>
</html>

selenium test:

storeEval | new Array("Volvo", "Saab", "Opel", "Audi") | Cars
storeEval | new Array("v", "s", "o","a") | CarIDs
storeEval | storedVars['Cars'][0]
storeEval | storedVars['CarIDs'][0]
select | //select[@id="cars"] | label=${CarName}
select | //select[@id="cars"] | id=${CarID}

All passed and worked. The label= expression is optional. The 0 can be exchanged for random number Math.floor(Math.random()*4) with possible use of storedVars['Array'].length or whole test case could be done in cycle with SelBlocks Firefox/Selenium-IDE addon or, if you will decide for Selblocks, consider use of XML data and datadriven tests with forXML command. It is working well.

I personally use following javascript:

javascript{
   var Cars=['Volvo', 'Saab', 'Opel', 'Audi'];
   Cars[Math.floor(Math.random()*Cars.length)]
}

to select random value for smoke testing in single store command:

store | javascript{var Cars=['Volvo', 'Saab', 'Opel', 'Audi']; Cars[Math.floor(Math.random()*Cars.length)]} | CarID
select | //select[@id="cars"] | id=${CarID}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.