无法在selenium webdriver中实例化类型Select

问题描述 投票:1回答:3

我试图模拟一个测试用例,我必须从多选框中选择多个选项。我可以使用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

}

有人可以帮我摆脱这个问题

selenium-webdriver
3个回答
12
投票

尝试使用Select导入包。您可以使用以下方法将其导入项目:

import org.openqa.selenium.support.ui.Select;


1
投票

尝试导入Select支持包:

import org.openqa.selenium.support.ui.Select;

0
投票
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", 
© www.soinside.com 2019 - 2024. All rights reserved.