我正在尝试选择Selenium webdriver中的下拉列表。
这是我的代码:
package Select;
import org.testng.annotations.Test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.jetty.html.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
public class NewTest {
public WebDriver driver= new FirefoxDriver();
@BeforeTest
public void setup(){
//Open URL in Browser
driver.get("http://www.homeshop18.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Maximize the window.
driver.manage().window().maximize();
}
@Test
public void EnterData(){
Select select = new Select(driver.findElement(By.xpath("//[@id='q_category']")));
select.deselectAll();
select.selectByVisibleText("15095");
}
}
但我收到此错误:
The constructor Select(WebElement) is undefined
答案 0 :(得分:1)
您收到此错误是因为您导入了其他Select
类。
请从您的导入中删除以下声明,它可以正常工作: -
import org.openqa.jetty.html.Select; // This one you have to remove
要与Select WebElement
合作,您需要import
来自Select
Selenium
import org.openqa.selenium.support.ui.Select; // This one you have to use
希望它有所帮助!