Geckodriver / FirefoxDriver / Selenium - 如何打开(空白)起始页或清除页面?

Geckodriver / FirefoxDriver / Selenium - How to open (empty) start page or clear page?

我想在页面加载后清除它。最好的方法是加载 Firefox 的起始页,这对我来说是一个空白页。

背景是,我得到一些框架相同但数据不同的页面。就像您循环获取维基百科文章的历史一样。有时它似乎使用的是最后一个,已经得到的页面,而不是新页面。我不知道为什么会发生这种情况,但这种情况很少发生。在这种情况下,我会通过清除页面或其他站点得到一个错误。

一个快速而肮脏的解决方案是加载另一个页面(如 google 或 bing),但这会导致额外的数据流量,这并不是我想要的。

下面唯一的评论是我想导航到空默认页面或清除加载页面的行。

public class myGecko 
{

    WebDriver   FireFoxDriver;
    
    public void openFireFoxSingle() 
    {
        try 
        {
            System.setProperty("webdriver.gecko.driver","C:\Gecko.exe");   
            File pathBinary             = new File("F:\Firefox.exe");      
            FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
            
            
            firefoxBinary.addCommandLineOptions("--disable-extensions");
            
            DesiredCapabilities desired = new DesiredCapabilities();
            FirefoxOptions options      = new FirefoxOptions();                                                 
            
            desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));            
            FireFoxDriver = new FirefoxDriver(options);                                                         
            FireFoxDriver.manage().window().maximize();                                                         
        }
        catch(Exception e) {}
    }
    
    public void getPage(String myLink) 
    {
        try 
        {
            FireFoxDriver.get(myLink);
            WebElement myDynamicElement = (new WebDriverWait(FireFoxDriver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("col-content")));
            
            Thread.sleep(2000L);
            
            // HERE NOW NAVIGATE BACK TO START PAGE or an EMPTY PAGE or CLEAR THE PAGE
        }
        catch(Exception e) {return; }
        
        
    }
}

如何清除页面 or/and 导航回空的默认页面?

对我有用但导致页面加载三次的是:

        FireFoxDriver.get(myLink);
        FireFoxDriver.navigate().refresh();
        FireFoxDriver.get(myLink);

有了这个我完全确定,页面已经刷新了。

我使用最新的 Firefox 98.0、Selenium 4.12 和 Geckodriver 0.3.0 但是我也遇到了旧版本(Selenium 3.x 和旧 Gecko)的问题。

答案是创建FireFoxDriver.get("about:blank");