Java 硒的问题?
我刚刚开始使用selenium,但是,当我运行页面上给出的示例时,我遵循了开始的步骤:Java 硒的问题?,java,selenium,Java,Selenium,我刚刚开始使用selenium,但是,当我运行页面上给出的示例时,我遵循了开始的步骤: package org.openqa.selenium.example; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org
package org.openqa.selenium.example;
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 Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
package org.openqa.selenium.example;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.support.ui.ExpectedCondition;
导入org.openqa.selenium.support.ui.WebDriverWait;
公共类示例{
公共静态void main(字符串[]args){
//创建Firefox驱动程序的新实例
//请注意,代码的其余部分依赖于接口,
//而不是执行。
WebDriver=newfirefoxdriver();
//现在用这个来访问谷歌
驱动程序。获取(“http://www.google.com");
//或者也可以这样做
//驱动程序。导航()。到(“http://www.google.com");
//按名称查找文本输入元素
WebElement=driver.findElement(By.name(“q”));
//输入要搜索的内容
元素。sendKeys(“Cheese!”);
//现在提交表单。WebDriver将从元素中为我们找到表单
元素。提交();
//检查页面的标题
System.out.println(“页面标题为:“+driver.getTitle());
//谷歌的搜索是用JavaScript动态呈现的。
//等待页面加载,10秒后超时
(新的WebDriverWait(驱动程序,10))。直到(新的预期条件(){
公共布尔应用(WebDriver d){
返回d.getTitle().toLowerCase().startsWith(“cheese!”);
}
});
//应该看到:“奶酪!-谷歌搜索”
System.out.println(“页面标题为:“+driver.getTitle());
//关闭浏览器
driver.quit();
}
}
我得到了一堆编译错误。有人知道会发生什么吗?我对这个系统不是很熟悉,因为我刚刚开始使用它。我遵循了上面链接的页面上给出的所有说明,编译错误不会消失:
Selenium2Example.java:3: error: cannot find symbol
import org.openqa.selenium.By;
^
symbol: class By
location: package org.openqa.selenium
Selenium2Example.java:4: error: cannot find symbol
import org.openqa.selenium.WebDriver;
^
symbol: class WebDriver
location: package org.openqa.selenium
Selenium2Example.java:5: error: cannot find symbol
import org.openqa.selenium.WebElement;
^
symbol: class WebElement
location: package org.openqa.selenium
Selenium2Example.java:6: error: package org.openqa.selenium.firefox does not exist
import org.openqa.selenium.firefox.FirefoxDriver;
^
Selenium2Example.java:7: error: package org.openqa.selenium.support.ui does not exist
import org.openqa.selenium.support.ui.ExpectedCondition;
^
Selenium2Example.java:8: error: package org.openqa.selenium.support.ui does not exist
import org.openqa.selenium.support.ui.WebDriverWait;
^
Selenium2Example.java:15: error: cannot find symbol
WebDriver driver = new FirefoxDriver();
^
symbol: class WebDriver
location: class Selenium2Example
Selenium2Example.java:15: error: cannot find symbol
WebDriver driver = new FirefoxDriver();
^
symbol: class FirefoxDriver
location: class Selenium2Example
Selenium2Example.java:23: error: cannot find symbol
WebElement element = driver.findElement(By.name("q"));
^
symbol: class WebElement
location: class Selenium2Example
Selenium2Example.java:23: error: cannot find symbol
WebElement element = driver.findElement(By.name("q"));
^
symbol: variable By
location: class Selenium2Example
Selenium2Example.java:36: error: cannot find symbol
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
^
symbol: class ExpectedCondition
location: class Selenium2Example
Selenium2Example.java:36: error: cannot find symbol
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
^
symbol: class WebDriverWait
location: class Selenium2Example
12 errors
Selenium2Example.java:3:错误:找不到符号
导入org.openqa.selenium.By;
^
符号:class By
位置:package org.openqa.selenium
Selenium2Example.java:4:错误:找不到符号
导入org.openqa.selenium.WebDriver;
^
符号:类WebDriver
位置:package org.openqa.selenium
Selenium2Example.java:5:错误:找不到符号
导入org.openqa.selenium.WebElement;
^
符号:类WebElement
位置:package org.openqa.selenium
Selenium2Example.java:6:错误:包org.openqa.selenium.firefox不存在
导入org.openqa.selenium.firefox.FirefoxDriver;
^
Selenium2Example.java:7:错误:包org.openqa.selenium.support.ui不存在
导入org.openqa.selenium.support.ui.ExpectedCondition;
^
Selenium2Example.java:8:错误:包org.openqa.selenium.support.ui不存在
导入org.openqa.selenium.support.ui.WebDriverWait;
^
Selenium2Example.java:15:错误:找不到符号
WebDriver=newfirefoxdriver();
^
符号:类WebDriver
位置:Selenium2类示例
Selenium2Example.java:15:错误:找不到符号
WebDriver=newfirefoxdriver();
^
符号:FirefoxDriver类
位置:Selenium2类示例
Selenium2Example.java:23:错误:找不到符号
WebElement=driver.findElement(By.name(“q”));
^
符号:类WebElement
位置:Selenium2类示例
Selenium2Example.java:23:错误:找不到符号
WebElement=driver.findElement(By.name(“q”));
^
符号:变量由
位置:Selenium2类示例
Selenium2Example.java:36:错误:找不到符号
(新的WebDriverWait(驱动程序,10))。直到(新的预期条件(){
^
符号:类ExpectedCondition
位置:Selenium2类示例
Selenium2Example.java:36:错误:找不到符号
(新的WebDriverWait(驱动程序,10))。直到(新的预期条件(){
^
符号:WebDriverWait类
位置:Selenium2类示例
12个错误
您需要将Selenium添加到类路径中,因此您不是在使用Maven编译,或者pom文件中存在配置错误。您需要将Selenium添加到类路径中,因此您不是在使用Maven编译,或者pom文件中存在配置错误。您的pom文件中缺少Selenium jar文件项目。您可以从这里下载jar,因为您的项目中缺少selenium jar文件。如果您使用maven,则可以从这里下载jar,然后将依赖项添加到POM。如果您使用ant,则将其添加到类路径。如果您能够看到selenium jar文件,则只需签入项目依赖项。Side注意当您在ide中输入WebDriver并点击Ctrl+Space时会发生什么?您能看到intellisense弹出窗口吗?如果不能,那么您仍然没有添加selenium jar文件。如果您使用maven,那么将依赖项添加到POM中。如果您使用ant,那么将其添加到类路径中。如果需要,只需签入项目依赖项即可能够查看selenium jar文件。请注意,当您输入WebDriver并在IDE中按Ctrl+Space时会发生什么?您是否能够看到intellisense弹出窗口?如果没有,则您仍然没有添加selenium jar文件。不确定这是否是原因,但请检查您的类路径中是否有hamcrest以及selenium库。不确定这是否是原因,但检查类路径中是否也有hamcrest,以及