Selenium Select2 command for drop-down box

空扰寡人 提交于 2019-12-23 05:06:05

问题


am new to selenium and in my previous question Selenium IDE command for input type hidden it is using select2 please help me with the command to selection option for drop-down list.

i tried looking in here https://gist.github.com/3683275 but it doesn't seem to work for me

mouseDown('//a[@class="select2-choice select2-default"][1]')
mouseUp('//li[contains(@class,"select2-result")][1]')

回答1:


These commands open the options list, wait for it to appear, and finally choose the option labelled "California". Select2 can be customized in different ways, hope these commands work for you.

mouseDown      css=.select2-choice > div > b
waitForVisible css=.select2-results
mouseUp        css=.select2-result-label:contains('California') 



回答2:


WebElement element = driver.findElements(By.xpath(/*xpath*/));

Select select = new Select(element);

select.selectByVisibleText(value);



回答3:


Alternatively, it can also be handled by using clickAt()

clickAt('//a[@class="select2-choice select2-default"][1]');
waitForVisible("css=.select2-results");
clickAt('//li[contains(@class,"select2-result")][1]');


来源:https://stackoverflow.com/questions/13728551/selenium-select2-command-for-drop-down-box

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