-1
目前,我有这个代码。选择硒中的下拉项目
Select dropdown = new Select(driver.findElement(By.id("pgList")));
dropdown.selectByVisibleText("TestCustomerGroup070615");
driver.findElement(By.id("select1")).click();
我也导入了导入org.openqa.selenium.support.ui.Select; ,但它似乎没有做它说的应该做的事。
而且我认为它应该被列入我调用此同时打开一个新的窗口:
String winHandleBefore = driver.getWindowHandle();
driver.findElement(By.id("addGlobal")).click();
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
Select dropdown = new Select(driver.findElement(By.id("pgList")));
dropdown.selectByVisibleText("TestCustomerGroup070615");
driver.findElement(By.id("select1")).click();
driver.close();
driver.switchTo().window(winHandleBefore);
出了什么问题?
此错误弹出:
Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"
什么似乎是问题? – FazoM
它打开新窗口,但根本没有做任何事情。 –
您是否在新窗口或主窗口上执行操作。先关闭主窗口,然后切换到新窗口。然后继续在新窗口中进行操作。 –