Java 在selenium web驱动程序中加载URL的最佳方法是什么?

Java 在selenium web驱动程序中加载URL的最佳方法是什么?,java,selenium,web-scraping,Java,Selenium,Web Scraping,我正在尝试加载URL:使用SeleniumWeb驱动程序 使用WebDriver的.get(url)方法 driver.get(URL). 使用JavascriptExecutor ((JavascriptExecutor) pRobot.getDriver()).executeScript("window.location='URL'"); 以上哪种方法加载URL需要更多时间 driver.get(URL) 与JavascriptExecutor相比,这是启动url的最佳方法 .ge

我正在尝试加载URL:使用SeleniumWeb驱动程序

  • 使用WebDriver的.get(url)方法

    driver.get(URL).
    
  • 使用JavascriptExecutor

    ((JavascriptExecutor) pRobot.getDriver()).executeScript("window.location='URL'");
    
  • 以上哪种方法加载URL需要更多时间

    driver.get(URL)
    
  • 与JavascriptExecutor相比,这是启动url的最佳方法
  • .get(url)方法将等待url加载到您的浏览器上,而不是JavascriptExecutor上

  • 如果你谈论的是哪一个是快速的,答案是javascript,这是SaiPawan提到的显而易见的原因

    您应该使用哪一个,这取决于您的用例

    browser = webdriver.Firefox(profile)
    last_time = time.time()
    browser.get("https://google.com")
    print "driver.get() time = %s" % str(time.time() - last_time)
    last_time = time.time()
    browser.execute_script("window.location='https://www.google.com'")
    print "navigation through javascript time = %s" % str(time.time() - last_time)
    
    执行输出

    driver.get() time = 0.712184906006
    navigation through javascript time = 0.116823911667