java 如何在 webdriver 中导入选择类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29292280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to import select class in webdriver?
提问by sirisha gorrela
I tried importing select class in my program using selenium webdriver, but I am not able to import the predefined package.
我尝试使用 selenium webdriver 在我的程序中导入 select 类,但我无法导入预定义的包。
Can anyone please guide me on this?
任何人都可以请指导我吗?
package com.siri.dev;
import org.apache.bcel.generic.Select;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MyntraTests {
private WebDriver driver;
@Before
public void setup() {
intializedriver("firefox");
}
@Test
public void get() {
driver.get("http://www.myntra.com");
driver=waitForPageLoaded(driver);
driver.manage().window().maximize();
System.out.println("Page opened successfully");
WebElement element = driver.findElement(By.className("tab"));
org.openqa.selenium.support.ui.Select elem = new Select(element);
elem.selectByVisibleText("BIBA");
}
private void intializedriver(String browser) {
// TODO Auto-generated method stub
driver = new FirefoxDriver();
driver.manage().window().maximize();
}
回答by Saifur
import org.openqa.selenium.support.ui.Select;
Use
利用
Select selectElement = new Select(driver.findElement(By.cssSelector("")));
回答by Vivek Singh
The reason you are having this
你有这个的原因
org.openqa.selenium.support.ui.Select elem = new Select(element);
org.openqa.selenium.support.ui.Select elem = new Select(element);
is cause you have imported a wrong class imported already
是因为你已经导入了一个错误的类
import org.apache.bcel.generic.Select;
导入 org.apache.bcel.generic.Select;
remove that import by deleting it and then
通过删除它然后删除该导入
import org.openqa.selenium.support.ui.Select
导入 org.openqa.selenium.support.ui.Select
If you are using Eclipse you can always remove unused imports by ctrl+shift+o.
如果您使用 Eclipse,您可以随时通过ctrl+shift+o删除未使用的导入。
回答by Rameshwar
Selectis a class of package org.openqa.selenium.support.ui
Select是一类包org.openqa.selenium.support.ui
So you are supposed to do a import statement as follows:
所以你应该做一个导入语句如下:
import org.openqa.selenium.support.ui.Select;
and then you can do your task as:
然后你可以做你的任务:
Select elem = new Select(element);
elem.selectByVisibleText("BIBA");
U have imported a wrong package : import org.apache.bcel.generic.Select;
你导入了错误的包:import org.apache.bcel.generic.Select;
回答by Aaron Mansheim
If you use Maven, you will want to know that packages under org.openqa.selenium.support
are in artifact selenium-support
. That does not get pulled in along with selenium-api
or any of the selenium-*-driver
artifacts. You can refer to the Selenium Maven information.
如果你使用 Maven,你会想知道下面的包org.openqa.selenium.support
在 artifact 中selenium-support
。这不会与selenium-api
任何selenium-*-driver
工件一起被拉入。您可以参考Selenium Maven 信息。