Path: blob/trunk/rb/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb
1990 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21#22# @api private23#2425module DriverExtensions26module UploadsFiles27#28# Set the file detector to pass local files to a remote WebDriver.29#30# The detector is an object that responds to #call, and when called31# will determine if the given string represents a file. If it does,32# the path to the file on the local file system should be returned,33# otherwise nil or false.34#35# Example:36#37# driver = Selenium::WebDriver.for :remote38# driver.file_detector = lambda do |args|39# # args => ["/path/to/file"]40# str = args.first.to_s41# str if File.exist?(str)42# end43#44# driver.find_element(:id => "upload").send_keys "/path/to/file"45#46# By default, no file detection is performed.47#48# @api public49#5051def file_detector=(detector)52raise ArgumentError, 'detector must respond to #call' unless detector.nil? || detector.respond_to?(:call)5354bridge.file_detector = detector55end56end # UploadsFiles57end # DriverExtensions58end # WebDriver59end # Selenium606162