def driver(self):
"""Returns a Selenium WebDriver instance of the type requested in the
configuration."""
from dallinger.config import get_config
config = get_config()
if not config.ready:
config.load()
driver_url = config.get('webdriver_url', None)
driver_type = config.get('webdriver_type', 'phantomjs').lower()
if driver_url:
capabilities = {}
if driver_type == 'firefox':
capabilities = webdriver.DesiredCapabilities.FIREFOX
elif driver_type == 'chrome':
capabilities = webdriver.DesiredCapabilities.CHROME
elif driver_type == 'phantomjs':
capabilities = webdriver.DesiredCapabilities.PHANTOMJS
else:
raise ValueError(
'Unsupported remote webdriver_type: {}'.format(driver_type))
driver = webdriver.Remote(
desired_capabilities=capabilities,
command_executor=driver_url
)
elif driver_type == 'phantomjs':
driver = webdriver.PhantomJS()
elif driver_type == 'firefox':
driver = webdriver.Firefox()
elif driver_type == 'chrome':
driver = webdriver.Chrome()
else:
raise ValueError(
'Unsupported webdriver_type: {}'.format(driver_type))
driver.set_window_size(1024, 768)
logger.info("Created {} webdriver.".format(driver_type))
return driver
评论列表
文章目录