问题
I am trying to set a dropdown value using javascript in selenium IDE, but not able to figure out which selenium command to use.
回答1:
Selenium IDE command to execute a javascript statement: runScript
with the javascript statement as argument.
Example (can be run on Google startpage):
<tr> <td>runScript</td> <td>document.getElementById('searchText').setAttribute("value", "hello");</td> <td></td> </tr>
回答2:
You can run a script (like above) and set the option you want to "selected".
You can also do it with the selenium select command:
Command: select
Target: id="yourDropDownId"
Value: label="yourOption"
or html source
<tr> <td>select</td> <td>id="yourDropDownId"</td> <td>label="yourOption"</td> </tr>
回答3:
Assuming the dropdown has id myDropdown
and the value you want to select is valueToSelect
, try this:
selenium.select("//select[@id='myDropdown']", "label=valueToSelect");
来源:https://stackoverflow.com/questions/19970824/which-selenium-ide-command-should-i-use-to-execute-a-javascript-statement