Selenium Select2 command for drop-down box

2019-06-13 16:21发布

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]')

3条回答
Fickle 薄情
2楼-- · 2019-06-13 16:36

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') 
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-06-13 16:47

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]');
查看更多
干净又极端
4楼-- · 2019-06-13 17:00
WebElement element = driver.findElements(By.xpath(/*xpath*/));

Select select = new Select(element);

select.selectByVisibleText(value);
查看更多
登录 后发表回答