硒“无法杀死已退出的进程”

时间:2019-12-03 21:00:15

标签: java selenium

每次我运行服务器上的.jar时。我遇到了错误。当我在Windows上运行该应用程序时,一切正常。

  

org.openqa.selenium.WebDriverException:无效的参数:不能   杀死一个退出的进程       构建信息:版本:“未知”,修订版:“未知”,时间:“未知”       系统信息:主机:'autoru',ip:'127.0.1.1',操作系统名称:'Linux',os.arch:'amd64',os.version:'4.15.0-70-generic',java.version :   '1.8.0_222'       驱动程序信息:driver.version:FirefoxDriver       远程堆栈跟踪:         在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)处         在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)         在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)         在java.lang.reflect.Constructor.newInstance(Constructor.java:423)         在org.openqa.selenium.remote.W3CHandshakeResponse.lambda $ errorHandler $ 0(W3CHandshakeResponse.java:62)         在org.openqa.selenium.remote.HandshakeResponse.lambda $ getResponseFunction $ 0(HandshakeResponse.java:30)         在org.openqa.selenium.remote.ProtocolHandshake.lambda $ createSession $ 0(ProtocolHandshake.java:126)         在java.util.stream.ReferencePipeline $ 3 $ 1.accept(ReferencePipeline.java:193)         在java.util.Spliterators $ ArraySpliterator.tryAdvance(Spliterators.java:958)         在java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)         在java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)         在java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)         在java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)         在java.util.stream.FindOps $ FindOp.evaluateSequential(FindOps.java:152)         在java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)         在java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:531)         在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)         在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)         在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)         在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)         在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)         在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)         在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:131)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:147)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:125)         在com.company.bot.Test.Test.connect(Test.java:24)         在com.company.bot.bot.Parsing.ParsinTop.start(ParsinTop.java:44)         在com.company.bot.bot.Parsing.ParsinTop.run(ParsinTop.java:24)         在java.lang.Thread.run(Thread.java:748)

代码

    public class Test {

    public String connect(String url) {
        DataBase dataBase = new DataBase();
        dataBase.connect();
        String result = "";
        try {
            System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
            WebDriver driver = new FirefoxDriver();
            //url = url.replace("https://auto.ru/cars/", "https://auto.ru/moskva/cars/");
            driver.get(url);
            System.out.println("Connect to " + url);
            driver.findElements(By.xpath("//div[@class='button button_blue']")).get(0).click();
            System.out.println("After accept");

            try {
                Thread.sleep(10000);
                driver.findElements(By.xpath("//div[@class='CardPhone-module__phone OfferNewStickedBlock-module__contacts CardPhone-module__preview']")).get(0).click();
                System.out.println("Click contack");
            } catch (Exception e){
                driver.quit();
                connect(url);
                e.printStackTrace();
            }

            while(result.equals("") || result.equals(" ")) {
                Document document = Jsoup.parse(driver.getPageSource());
                Elements elements = document.getElementsByClass("CardGroupListingItem-module__footerCell_left");
                Element el = elements.get(0).getElementsByClass("Link CardDealerName-module__dealerName").get(0);
                result = el.attr("href");
            }

            driver.quit();
        } catch(Exception ex){
            ex.printStackTrace();
        }

        return result;
    }
}

出现这些错误后,许多geckodriver启动。还有

driver.quit();

不会杀死geckodriver进程。 如何解决?

0 个答案:

没有答案