java - 使用 Selelnium 时出现错误

标签 java selenium netbeans

我下载了独立服务器文件、驱动程序文件,然后复制到库中。我已经将 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/

相关文章:

java - java中递归打印树中的所有节点

java - Java实际上是否并行运行线程

java - AppEngine java 应用程序忽略 app.yaml

javascript - 如何使用 browsermob-proxy 和 nightwatch.js 监控 HTTP 调用?

java - 如何在 Netbeans IDE 中制作静态类

java - 应用程序仅在 Debug模式下运行

java - 跨类加载器转换?

python - 在 Python 中为 CSS 属性值解析呈现的 HTML

java - 访问网站时无法发送 key 或关闭弹出窗口

Java计算字符串字符个数的方法