CrossBrowserTesting Support

Support

  • Product
    • Live Testing
    • Automated Testing
    • Record & Replay
    • Visual Testing
  • API Docs
  • Blog
  • Live Q&A
  • Start Testing
CrossBrowserTesting Support » Selenium Testing » Uploading Files Via Selenium

Uploading Files Via Selenium

One of our customers came to us with a question about testing with a file upload.

I quickly responded it was not possible with the way we clear out all of virtual machines. What is a great feature for privacy is not such a great feature for testing file uploads 🙁

But Henry ( see his site here http://people.apache.org/~hchan/ ) was not convinced and came up with a fantastic solution.

This is the resource he passed me.
https://muthutechno.wordpress.com/2014/07/09/uploading-files-in-selenium…

The magic happens on the workstation side (where you are running your script), selenium will take the file you have locally and get it to the remote instance running at CrossBrowserTesting.com

Super cool stuff and once again really good detective work from Henry. Always great to learn something new.

See the article for what your HTML will look like, below is a sample of what your Python script might look like.


from selenium import webdriver
import time

caps = {}
caps[‘browser_api_name’] = ‘Chrome40x64’
caps[‘os_api_name’] = ‘Win8.1’
caps[‘screen_resolution’] = ‘1024×768’
caps[‘record_video’] = ‘true’
caps[‘record_network’] = ‘false’
caps[‘record_snapshot’] = ‘false’

USERNAME=””
AUTHKEY=””
CS = “http://” + USERNAME + “:” + AUTHKEY + “@hub.crossbrowsertesting.com:80/wd/hub”
driver = webdriver.Remote(desired_capabilities=caps,command_executor=CS)

time.sleep(5)

driver.get(“http://SOMEDOMAIN.com/testupload.html”)
time.sleep(5)
e = driver.find_element_by_id(“fileuploadField”)

# this filename is on your local workstation
e.send_keys(“c:\\projects\\2015\\06-jun\\selenium-fileupload\\677px-Mona_Lisa.jpg”)

time.sleep(5)

s = driver.find_element_by_id(“submit”)
s.click()

time.sleep(30)
driver.quit()

Related

Selenium Starting Guides

  • Python
  • Java
  • JavaScript
  • PHP
  • Ruby
  • C#
  • Selenium 101

More Help

  • Parallel Testing
  • Jenkins Integration
  • TeamCity Integration
  • Automation Capabilities
  • Local Testing

See Our GitHub Examples


 



Think you need a human?

Our customer success team will be glad to help you with your question.

Contact Support

Still need a free trial?

Try CrossBrowserTesting free for 7 days and see how we make testing easier.

Start Today

Want the latest tips?

Enter your email and we’ll send you tutorials and browser testing strategies right to your inbox.


Product

  • Live Testing
  • Automated Testing
  • Visual Testing
  • Local Testing
  • Integrations

Resources

  • Browsers & Devices
  • Blog
  • Webinars
  • Security
  • ROI Calculator

Support

  • Help Center
  • CBT Community
  • API Docs
  • Automation Docs
  • Schedule A Demo
  • Enterprise Request

Company

    • About Us
    • Contact Us
    • Careers
    • Terms of Use
    • 1-888-927-6973

© 2019 CrossBrowserTesting.com, LLC. All rights reserved.