下面的代码转到一个页面,找到下拉菜单并单击列表中的第一个菜单。如何调整以下代码以便能够选择列表中的第二个或第三个项目?
await browser
.findElement(By.css('#historyTabDropdown ul>li>a'))
.then(e => e.click());
最佳答案
尝试使用 css 选择器 nth-child。 CSS 为 li:nth-child(2)
await browser
.findElement(By.css('#historyTabDropdown ul>li:nth-child(2)>a'))
.then(e => e.click());
关于javascript - Selenium JavaScript 单击下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53325486/