截屏
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Testing { public void myTest() throws Exception {
WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
driver.get("http://www.google.com");
// RemoteWebDriver does not implement the TakesScreenshot class
// if the driver does have the Capabilities to take a screenshot
// then Augmenter will add the TakesScreenshot methods to the instance
WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE); } }
from selenium import
webdriver driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.FIREFOX)
driver.get("http://www.google.com") driver.get_screenshot_as_file('/Screenshots/google.png')
require 'rubygems'
require 'selenium-webdriver'
begin driver = Selenium::WebDriver.for :remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => :firefox driver.get "http://www.google.com" driver.save_screenshot "/Screenshots/google.png" ensure driver.quit end
使用Firefox配置
FirefoxProfile fp = new FirefoxProfile(); // set something on the profile...
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, fp);
WebDriver driver = new RemoteWebDriver(dc);
from selenium import
webdriver fp = webdriver.FirefoxProfile() # set something on the profile...
driver =webdriver.Remote(desired_capabilities=webdriver.
DesiredCapabilities.FIREFOX, browser_profile=fp)
使用Chrome选项
ChromeOptions options = new ChromeOptions(); // set some options
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(dc);
from selenium import
webdriver options = webdriver.ChromeOptions() # set some options
driver = webdriver.Remote(desired_capabilities=options.to_capabilities())