我在代码中使用 react-select V2
并使用多选,我的组件如下所示:
<Select
isMulti
className="basic-multi-select"
classNamePrefix="select"
options={ this.getTransformedOptions() }
components={{ Placeholder, DropdownIndicator }}
placeholder={this.props.placeholderText}
onChange={this.props.onChange('multi')}
/>
我使用 mocha、node、selenium 和 chrome 驱动程序为我的应用程序创建集成测试,因此对于此页面,我想简单地测试打开下拉菜单、选择一些选项、删除一些选项等。
如果我将 menuIsOpen={true}
传递给组件,我可以使用以下命令轻松单击该元素:
driver.findElement(By.css('.select__menu div[id="react-select-2-option-0"]')).click();
但是,我仍然无法以编程方式单击打开菜单。有谁知道我如何使用与上面类似的命令来做到这一点?
最佳答案
我能够通过使用 selenium actions
和 mouseDown
方法解决该问题,如下所示:
driver.wait(until.elementLocated(By.css('div.select__dropdown-indicator')), TEST_TIMEOUT);
currentElement = driver.findElement(By.css("div.select__dropdown-indicator"));
driver.actions().mouseDown(currentElement).click().perform(); // expand drop down menu
currentElement = driver.findElement(By.className("select__input"));
driver.actions().mouseDown(currentElement).click().perform();
driver.findElement(By.css('.select__menu div[id="react-select-2-option-0"]')).click();
关于node.js - 如何使用mocha、node和selenium集成测试react-select多选下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56248599/