我试图模拟一个测试用例,我必须从多选框中选择多个选项。我可以使用select来做到这一点。但是,一旦我实例化选择,我就会得到以下错误。
“无法实例化类型选择”
我的代码是:
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
}
有人可以帮我摆脱这个问题
尝试使用Select
导入包。您可以使用以下方法将其导入项目:
import org.openqa.selenium.support.ui.Select;
尝试导入Select
支持包:
import org.openqa.selenium.support.ui.Select;
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",