51Testing软件测试论坛

标题: 自动化第一步就卡住了 有没有大佬帮忙看看这咋回事啊 [打印本页]

作者: jiyihe    时间: 2019-5-13 15:30
标题: 自动化第一步就卡住了 有没有大佬帮忙看看这咋回事啊
本帖最后由 jiyihe 于 2019-5-13 15:39 编辑

只能弹出浏览器 但是没有跳转

这是源码




import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LuanchFirefox {

        public static void main(String[] args) {
               
                //System.setProperty("webdriver.firefox.marionette", ".\\Tools\\geckodriver.exe");
                System.setProperty("webdriver.firefox.bin","E:\\Mozilla Firefox\\firefox.exe");
                System.setProperty("webdriver.gecko.driver", ".\\tool\\geckodriver.exe");
                //初始化一个火狐浏览器实例,实例名称叫driver
                                WebDriver driver = new FirefoxDriver();
                                //最大化窗口
                                driver.manage().window().maximize();
                                //设置隐性等待时间
                                driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
                               
                                // get()打开一个站点
                                driver.get("https://www.baidu.com");
                                //getTitle()获取当前页面title的值
                                System.out.println("当前打开页面的标题是: "+ driver.getTitle());
                               
                                //关闭并退出浏览器
                                driver.quit();
                               
        }
}



下面运行报错
1557733073530        geckodriver        INFO        Listening on 127.0.0.1:47825
1557733073990        geckodriver::marionette        INFO        Starting browser \\?\E:\Mozilla Firefox\firefox.exe with args ["-marionette"]
1557733075678        addons.webextension.screenshots@mozilla.org        WARN        Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1557733075678        addons.webextension.screenshots@mozilla.org        WARN        Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1557733075679        addons.webextension.screenshots@mozilla.org        WARN        Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1557733075819        Marionette        TRACE        Received observer notification profile-after-change
1557733076353        Marionette        TRACE        Received observer notification toplevel-window-ready
1557733076383        Marionette        TRACE        Received observer notification command-line-startup
1557733076383        Marionette        TRACE        Received observer notification nsPref:changed
1557733076383        Marionette        DEBUG        Init aborted (running=false, enabled=true, finalUIStartup=false)
1557733077438        Marionette        TRACE        Received observer notification toplevel-window-ready
1557733079717        Marionette        TRACE        Received observer notification sessionstore-windows-restored
1557733079717        Marionette        TRACE        GFX sanity window detected, waiting until it has been closed...
1557733080543        Marionette        TRACE        Received observer notification domwindowclosed
1557733080543        Marionette        TRACE        Waiting until startup recorder finished recording startup scripts...
1557733080552        Marionette        TRACE        All scripts recorded.
1557733080552        Marionette        DEBUG        Setting recommended pref app.normandy.api_url to
1557733080553        Marionette        DEBUG        Setting recommended pref app.update.disabledForTesting to true
1557733080553        Marionette        DEBUG        Setting recommended pref browser.contentblocking.introCount to 99
1557733080554        Marionette        DEBUG        Setting recommended pref browser.safebrowsing.passwords.enabled to false
1557733080554        Marionette        DEBUG        Setting recommended pref browser.urlbar.suggest.searches to false
1557733080556        Marionette        DEBUG        Setting recommended pref datareporting.policy.dataSubmissionPolicyAccepted to false
1557733080556        Marionette        DEBUG        Setting recommended pref dom.disable_beforeunload to true
1557733080556        Marionette        DEBUG        Setting recommended pref dom.file.createInChild to true
1557733080557        Marionette        DEBUG        Setting recommended pref network.http.phishy-userpass-length to 255
1557733080557        Marionette        DEBUG        Setting recommended pref toolkit.cosmeticAnimations.enabled to false
1557733080639        Marionette        INFO        Listening on port 11981
1557733080639        Marionette        DEBUG        Remote service is active
1557733081521        Marionette        DEBUG        Accepted connection 0 from 127.0.0.1:12024
1557733081523        Marionette        DEBUG        0 -> [0,1,"newSession",{"capabilities":{"desiredCapabilities":{}}}]
1557733081524        Marionette        DEBUG        0 <- [1,1,{"error":"unknown command","message":"newSession","stacktrace":"WebDriverError@chrome://marionette/content/error.js:179: ... et@chrome://marionette/content/server.js:235:8\n_onJSONObjectReady/<@chrome://marionette/content/transport.js:493:9\n"},null]
五月 13, 2019 3:38:01 下午 org.openqa.selenium.remote.ErrorCodes toStatus
信息: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown error' (500 expected)
Exception in thread "main" org.openqa.selenium.WebDriverException: newSession
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'JIYIHE-PC', ip: '192.168.1.118', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
   0:           0x48916f - <no info>
   1:           0x489f59 - <no info>
   2:           0x439ced - <no info>
   3:           0x4473ea - <no info>
   4:           0x445128 - <no info>
   5:           0x41dbb1 - <no info>
   6:           0x407997 - <no info>
   7:           0x6bbb39 - <no info>
   8:           0x415b39 - <no info>
   9:           0x6b6043 - <no info>
  10:         0x76ed59cd - BaseThreadInitThunk
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
        at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
        at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$22(ProtocolHandshake.java:365)
        at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
        at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
        at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
        at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
        at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
        at LuanchFirefox.main(LuanchFirefox.java:19)


作者: xtloveplr520    时间: 2019-5-13 16:55
看一下FirefoxDriver 和Firefox浏览器版本不匹配
作者: jiyihe    时间: 2019-5-14 08:34
xtloveplr520 发表于 2019-5-13 16:55
看一下FirefoxDriver 和Firefox浏览器版本不匹配

已解决 谢谢大佬

作者: 赵佳乐SMILE    时间: 2019-5-20 08:40
xtloveplr520 发表于 2019-5-13 16:55
看一下FirefoxDriver 和Firefox浏览器版本不匹配






欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2