Selenium webdriver 无法在selenium webdriver中实例化类型Select
我试图模拟一个测试用例,在这个测试用例中,我必须从multipleselect框中选择multipleoption。我可以使用select来完成此操作。然而,当我实例化select时,我得到了以下错误 “无法实例化类型选择” 我的代码是:Selenium webdriver 无法在selenium webdriver中实例化类型Select,selenium-webdriver,Selenium Webdriver,我试图模拟一个测试用例,在这个测试用例中,我必须从multipleselect框中选择multipleoption。我可以使用select来完成此操作。然而,当我实例化select时,我得到了以下错误 “无法实例化类型选择” 我的代码是: import java.awt.List; import java.util.ArrayList; import junit.framework.Assert; import org.apache.bcel.generic.Select; import o
import java.awt.List;
import java.util.ArrayList;
import junit.framework.Assert;
import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SeleniumFormTesting {
//piece of code to open the browser in firefox
Select selectBox = new Select(driver.findElement(By
.cssSelector("select#id_contact")));
//in above select statement the error comes
}
有人能帮我解决这个问题吗?尝试使用
选择导入包。您可以使用以下方法将其导入到项目中:
import org.openqa.selenium.support.ui.Select代码>尝试导入选择支持包:
import org.openqa.selenium.support.ui.Select;
删除>>导入org.apache.bcel.generic.Select
仅使用>>导入org.openqa.selenium.support.ui.Select
对我来说,它成功了。谢谢你的回复,现在错误消失了。再次非常感谢,谢谢!我也遇到了同样的奇怪问题。别忘了添加selenium支持
依赖项:在回答中添加一些描述请添加一个解释,说明为什么这对您有效,以及为什么您认为这在这种情况下可能有效。
import java.awt.List;
import org.apache.bcel.generic.Select;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SelectDOB {
public static void main(String[] args) {
//Code to open browser and facebook page
Select s = new Select(driver.findElement(By.xpath("//*[@id='day']")));
s.selectByVisibleText("10");
Select s = new Select(driver.findElement(By.xpath("//*[@id='month']")));
s.selectByVisibleText("May");
Select s = new Select(driver.fintdElement(By.xpath("//*[@id='year']")));
s.selectByVisibleText("1980");
}}
tried with this, still am getting error
Am getting "Cannot instantiate the type Select",