Java 我正在尝试获取我所在页面的url,但我可以';T

Java 我正在尝试获取我所在页面的url,但我可以';T,java,selenium,selenium-webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,每一个链接都在工作,但是“getCurrentUrl()”当它到达这个位置时,代码就停止了,页面甚至没有关闭。 我还尝试使用String currentUrl=driver.getCurrentUrl()

每一个链接都在工作,但是“getCurrentUrl()”当它到达这个位置时,代码就停止了,页面甚至没有关闭。 我还尝试使用
String currentUrl=driver.getCurrentUrl()(我是Selenium和编程方面的新手)

首先,您应该在
driver.navigate()到(url)之间添加一个延迟
驱动程序.getCurrentUrl()以允许加载页面。
现在
driver.getCurrentUrl()
以字符串形式返回一个值,这样您就可以按照
System.out.println(“当前URL:+driver.getCurrentUrl())所述打印它

然后添加
driver.quit()
退出

正如@prophet所提到的,您的
驱动程序.quit()放错了位置。
另外,
driver.getCurrentUrl()返回字符串。所以,除非你接受某个变量中的值并将其打印出来,否则你将不知道它在做什么。
因此,请执行以下操作:

public class WorkingWithChrome {

    ChromeDriver driver;
    
    String url = "http://qatechhub.com";
    String urlface = "https://www.facebook.com/";
    
    public void invokeBrowser() {
        
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\fabio\\eclipse-workspace\\libs\\chromedriver.exe");
        
    driver = new ChromeDriver();
    
    driver.manage().window().maximize();
    
    driver.get(url);
    
    
    }
    
    public void invokeBrowser2() {
        
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\fabio\\eclipse-workspace\\libs\\chromedriver.exe");
        
    driver = new ChromeDriver();
    
    driver.manage().window().maximize();
    
    driver.get(url);
    
    driver.navigate().to(urlface);
    
    driver.navigate().to(url);
    
    driver.getCurrentUrl();
    
    }   
    
    
    public static void main(String[] args) throws Exception {
        
        WorkingWithChrome wc = new WorkingWithChrome();
        
        wc.invokeBrowser();
        
        wc.invokeBrowser2();
        
}

    driver.quit();
    
    }
    
}

}

对不起,我没有正确解释自己,问题出在
驱动程序中。getCurrentUrl()
dosnet提供了测试未完成的站点的Url,我很忙:)谢谢你,它成功了:D
public void invokeBrowser2() {
    
System.setProperty("webdriver.chrome.driver", "C:\\Users\\fabio\\eclipse-workspace\\libs\\chromedriver.exe");
    
driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get(url);

driver.navigate().to(urlface);

driver.navigate().to(url);

System.out.println("Current URL : " + driver.getCurrentUrl());

driver.quit();