Firefox webdriver opens first run page all the time

前端 未结 8 2235
醉梦人生
醉梦人生 2020-12-03 04:09

How to disable this \"first run\" page once and for all for FF?

When FF driver is created, it opens tab with - https://www.mozilla.org/en-US/firefox/42.0/firstrun/le

8条回答
  •  伪装坚强ぢ
    2020-12-03 05:06

    The above solutions do not work, I've tried them. What did work for me, and probably will for you (if using firefox 43 or less) is:

        prof.setPreference("xpinstall.signatures.required", false);
        prof.setPreference("toolkit.telemetry.reportingpolicy.firstRun", false);
    

    The problems with 43 and selenium are twofold, the default signed extensions setting (to true) and the first run page. These lines solve both. These must be set programatically. If you try to set them in about:config (or directly in prefs.js) it will not affect the new browsers you open with selenium. It should be noted that they say firefox 44 will not allow you to set the signed extensions variable (so this will not work on 44).

    I include the codeblock from my now working code showing the correct use:

        FirefoxProfile prof = new FirefoxProfile();
        //FirefoxProfile prof = profile.getProfile("default");
        //prof.setPreference("browser.startup.homepage", proteinPageUrl);
        //prof.setPreference("startup.homepage_welcome_url", proteinPageUrl);
        //prof.setPreference("startup.homepage_welcome_url.additional", proteinPageUrl);
        prof.setPreference("xpinstall.signatures.required", false);
        prof.setPreference("toolkit.telemetry.reportingpolicy.firstRun", false);
        //Object socketLock = new Object();
        //synchronized(socketLock){
    
        //driver = new FirefoxDriver();
        driver = new FirefoxDriver(prof);
    
            //driver = forceInit();
            //driver.open();
        //}//end synch block
    
        //get protein page
        boolean done = true;
        do{
            driver.get(proteinPageUrl);
    
            final Wait waitDriver = new FluentWait(driver)
                       .withTimeout(30, java.util.concurrent.TimeUnit.SECONDS)
                       .pollingEvery(5, java.util.concurrent.TimeUnit.SECONDS);
            try{
                inputTextFeildElement = waitDriver.until(new Function(){
                    public WebElement apply(WebDriver diver){
                        return driver.findElement(By.name("term"));
                        }});
            }
    
            catch(NoSuchElementException nsee){
                //if not find by name try find by id
                if(driver.findElements(By.id("term")).size() != 0){
                    try{
                        inputTextFeildElement = driver.findElement(By.id("term"));
                        done = true;
                    } catch(NoSuchElementException nsee2){
                        synchronized(threadLogFile){
                            try {
                                threadLogWriter = new PrintWriter(new FileWriter(threadLogFile.getAbsoluteFile(), true));
                            } catch (IOException ioe) {
                                System.out.println("error opening file for append: " + ioe.getMessage());
                                ioe.printStackTrace();
                            }//catch
                            threadLogWriter.println("Thread Id: " + threadId + " with thread name: " + threadName + " fails to find input element by name or id to put accession: " + accession);
                            threadLogWriter.flush();
                            threadLogWriter.close();
                        }//synchronized
                        done = false;
                    }//catch nsee2
                }//catch nsee
            }
            catch(ElementNotVisibleException enve){
                done = false;
            }
        }while(!done);  
    

提交回复
热议问题