我有以下页面: http://live.guru99.com/index.php/mobile.html 。 我需要单击 Selenium 下拉列表中的“按名称排序”,尝试使用以下代码执行此操作:
public void f() {
verifyTitle(baseUrl, "Home page");
driver.findElement(By.cssSelector(".level0 ")).click();
verifyTitle(driver.getCurrentUrl(), "Mobile");
Select dd = new Select(driver.findElement(By.cssSelector("select[title=Sort By][css=1]")));
dd.selectByVisibleText("Name");
}
这段代码有什么问题?引号位置正确吗?
最佳答案
尝试使用以下代码:
Select dd = new Select(driver.findElement(By.cssSelector("select[title='Sort By']")));
dd.selectByVisibleText("Name");
希望对你有帮助!
关于java - Selenium 中的下拉 CSS 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48725191/