我下载了独立服务器文件、驱动程序文件,然后复制到库中。我已经将 selenium 文件中的“lib”文件夹也移动到了库位置。这是代码
package google.search;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class GoogleSearch {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Create a new WebDriver object (Firefox browser)
WebDriver bot = new HtmlUnitDriver();
// Navigating to google.com
bot.get("http://www.google.com");
// Find the text input element by its name
WebElement inputField = bot.findElement(By.name("q"));
// Send some keys into the textfield
inputField.sendKeys("Selenium is easy");
// Submit your text (to start a google search)
inputField.submit();
// Saving the page source code into a string
String pageSource = bot.getPageSource();
//Closing the Firefox browser and "shutdown" the WebDriver object
bot.quit();
}
}
即使现在我没有看到红色错误指示器,我仍然会遇到这个我以前从未遇到过的奇怪错误。谁能告诉我这是什么意思?
Feb 21, 2015 1:02:49 AM com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement addBehavior
WARNING: Unimplemented behavior: #default#userdata
最佳答案
您可以为 HtmlUnitDriver 添加 BrowserVersion 类对象以消除此错误,因为
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_24);
对象名称可以替换为不同的相应名称。这也不同于创建浏览器特定驱动程序,例如火狐驱动程序()
关于java - 使用 Selelnium 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28642712/