How to click a specified li for an autocomplete ul with Selenium IDE?

瘦欲@ 提交于 2019-12-02 01:37:22

The Selenium API gives you a number of ways to accomplish this. Since you don't have a traditional dropdown, you can't use the select command. Here are two solutions that click the second element in the autocomplete.

I created this JSFiddle to test the solutions. The clicked element will turn red.

Option 1: Use a CSS locator.

| Command               | Target                                               |
| open                  | http://jsfiddle.net/ansonhoyt/GYJW9/embedded/result/ |
| waitForElementPresent | css=ul.ui-autocomplete                               |
| click                 | css=ul.ui-autocomplete li.ui-menu-item:nth-child(2)  |

Note: Runs fast, and most people are comfortable with CSS, but this example requires that the targeted browser support the CSS3 nth-child selector.

Option 2: Use an XPath locator.

| Command               | Target                                               |
| open                  | http://jsfiddle.net/ansonhoyt/GYJW9/embedded/result/ |
| waitForElementPresent | css=ul.ui-autocomplete                               |
| click                 | //ul[contains(@class,'ui-autocomplete')]/li[2]       |

Note: XPath are less familiar for most people and can be very slow compared to CSS locators, especially in IE.

For more ideas, check out the documentation for Selenium IDE on locating elements and on the available Selenese commands.

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