我想在頁面加載后清除它。最好的方法是加載 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; }
}
}
How do I clear the page or/and navigate back to the empty default page?
What works for me but causes a page to load three times is:
FireFoxDriver.get(myLink);
FireFoxDriver.navigate().refresh();
FireFoxDriver.get(myLink);
With this I am completely sure, the page has been refreshed.
I use the latest Firefox 98.0, Selenium 4.12 and Geckodriver 0.3.0 But I had this issue also with older versions (Selenium 3.x and older Gecko).
uj5u.com熱心網友回復:
答案是創建 FireFoxDriver.get("about:blank");
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/443352.html
