Which selenium IDE command should I use to execute a javascript statement

瘦欲@ 提交于 2019-12-06 05:29:47

问题


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

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