how to select value from a drop down using Selenium IDE

孤者浪人 提交于 2019-12-21 09:34:16

问题


I am using Selenium IDE for the first and has no knowledge of automation scripting. So far i am able to manage using IDE but one issue is I am not able to select a value from drop down list randomly rather entering the index or label values manually every time.

Can anyone please help me with this.

Thank You


回答1:


I tried the below and it worked

Command: Select

Target : element Locator eg : id = card

Value : index=1




回答2:


General approach is firstly click on the element and then select value from the element.

For Clicking : 1.Command : click 2.target : element locator like xpath/id/class of the element eg. xpath=xpath of the element

For Selecting value: 1.Command : select 2.target : same element locator used for clicking 3.Value : Visible text you want to select / Index (You will get it by inspecting that element)




回答3:


Use command select(selectLocator, optionLocator), 'selectLocator' is the Id of the drop down from which the value is being selected and the 'optionLocator' is the value being selected.

For eg: say a drop down having Id="//select[@id='type'" with values like 'TypeA, TypeB, TypeC,...'. If you are selecting 'TypeA' from the drop down, your command should go like this:

selenium.select("//select[@id='type']", "label=TypeA");

I hope this will solve your problem.




回答4:


First get the total number of items in the dropdown. Use getSelectOptions to get an array of options of the select box. Then generate a random integer between 0 (inclusive) and the length of the array (exclusive. Then use select with an index locator to select the randomly chosen option.




回答5:


Use Command: KeyDown Target:css=input.comboboxname Value: \40

\40 is Down-Arrow Ascii value

then use \13 to make selection in value.(put value for command and Target same.)




回答6:


a quick and dirty javascript starting point:

<form>
  <select id="mySelect" onchange="myFunction()">
    <option>Apple</option>
    <option>Orange</option>
    <option>Pineapple</option>
    <option>Banana</option>
  </select>
</form>

<p id="demo" onclick="myFunction()" >click me</p>

<script>
function myFunction() {

   document.getElementById("mySelect").selectedIndex = Math.floor((Math.random() * document.getElementById("mySelect").options.length));

}
</script>

and the (somewhat) corresponding seleniumIDE runScript command:

command

runScript

target:

document.getElementById("myDropdown").selectedIndex = Math.floor(Math.random() * (document.getElementById("myDropdown").options.length-1))+1);

The +1 at the end is entirely optional: I've included it to prevent seleniumIDE from selecting the first




回答7:


Command: Select

Target: Search an Element of the website app. (name, id)

Value: What value/result do you want to see?

Example: As an user I want to select a list of colors of drop down list (Orange, Blue, Red) I want to select Blue color. This is a script.

Command: Select

Target: name=color

Value: Blue




回答8:


Tried below and it worked.

command: waitForNotVisible
target: class=sub-menu
value : index=3



回答9:


It will work with WaitForVisible command



来源:https://stackoverflow.com/questions/11213506/how-to-select-value-from-a-drop-down-using-selenium-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!