Selenium:简单的谷歌搜索给出错误?

时间:2015-03-01 08:40:56

标签: java selenium htmlunit google-search

我尝试使用HtmlUnitDriver运行简单的Google搜索程序,但是它给了我一个错误,我已经尝试了所有内容并用Google搜索了所有内容。但他们都没有为我工作。请帮忙。

这是我的计划:

Inside wrapped exception:
======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException]
com.gargoylesoftware.htmlunit.ScriptException: JavaException: java.lang.Exception: SyntaxError: An invalid or illegal string was specified. (script in https://www.google.co.in/?gfe_rd=cr&ei=GcvyVIpg5cDyB6X5gMgM from (104, 16767) to (105, 10)#104)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:591)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1078)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:393)
    at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:274)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:750)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:93)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:700)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:53)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:328)
    at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:162)
    at java.lang.Thread.run(Unknown Source)
Caused by: net.sourceforge.htmlunit.corejs.javascript.JavaScriptException: JavaException: java.lang.Exception: SyntaxError: An invalid or illegal string was specified. (script in https://www.google.co.in/?gfe_rd=cr&ei=GcvyVIpg5cDyB6X5gMgM from (104, 16767) to (105, 10)#104)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1006)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:582)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
    ... 19 more
JavaScriptException value = JavaException: java.lang.Exception: SyntaxError: An invalid or illegal string was specified.
======= EXCEPTION END ========
== CALLING JAVASCRIPT ==

  function () {
      Cja();
      _.Eja && _.uia();
      _.Jia();
      window.google.y.first = [];
      _.ua("google.x", _.Kia);
  }

======= EXCEPTION END ========

这是我的计划:

    driver.get("https://www.google.com/");
    Thread.sleep(5000);

    driver.findElement(By.name("q")).sendKeys(replaceMessage);
    Thread.sleep(4000);
    driver.findElement(By.name("btnG")).click();

好吧,我已经使用了btnGlst-ib。但没有人在工作〜

请帮助我:(

0 个答案:

没有答案