SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Uploading Files using
Selenium WebDriver
Uploading File
Uploading a file is a basic piece of
functionality found in the web
applications. Automating these sorts of
functionality is tricky in Selenium as
Selenium is limited to automating
browsers only, so when you are trying to
automate it you get prompted with a
dialog box that is just out of reach for
Selenium.
If "Upload button" is an Input Tag then
uploading a file is easy, you can simply
use SENDKEYS method. But if it is not
an Input Tag and you are looking to
automate it then you need third party
tools.
Ways to Upload File
1. Using SendKeys method.
2. Using AutoIt scripting.
3. Using Sikuli scripting.
Using SendKeys
Method
sendKeys method is basically used to
type some content into an input
field/tag.
The most basic way to perform the
upload of a file. Simply, get the file
upload element by using any locator you
want. And call the sendKeys() method to
set the value of the file to upload, the
value can be the absolute or relative
path of the file.
Limitation
This only works for INPUT tags.
<html>
<body>
<form>
Upload Your CV:
<input type="file" name="uploadfile" id="upfile">
</form>
</body>
</html>
driver.findElement(By.id("upfile")).sendKeys("C:filepathToUpload.txt");
The file path could be either absolute or relative file path.
Example : 1 (sendKeys)
Using AutoIt Scripting
If you have a button (Customized
button), not an input tag and when
clicking on the browse button, the
browser opens a window popup and to
select the file from system, And as we
know selenium will not support OS
controls. Here we need third party tool
like AutoIt.
AutoIt v3 is a freeware BASIC-like
scripting language designed for
automating the Windows GUI and
general scripting. It uses a
combination of simulated keystrokes,
mouse movement and
window/control manipulation in
order to automate web app and
desktop app.
How to begin with AutoIt
AutoIt setup is easy, there are lots of docs available on online for this. Basically, we need
following two things to be installed, to begin with.
1. Install AutoIt current version.
Go for AutoIt Full Installation, this will provide a basic version of the SciTE script
editor. To get full version of you have to download it separately.
https://www.autoitscript.com/site/autoit/downloads/
2. AutoIt Script Editor (Download the SciTE.exe and install; it is an editor which helps
in finding the commands.).
How to Write AutoIt Script
● Identify the Windows control, through AutoIt Windows Info tool (See Pic. 1).
● Click on Finder Tool and hover over the object for which you want the properties.
● It will capture the properties of pop up like Title, Class, Position, Size, Style and so on.
● Then with the help of captured properties, write a script in SciTE script editor or in
sublime and save the script with .au3 extension
How to Write AutoIt Script
● Now to compile the .au3 script you
can either use AutoIt Script to EXE
converter, which converts .au3 file
to .exe file or just right click your
.au3 script, it will show compile
options. Select compile to 64bit
(x64) or compile to 32bit (x86)
option and will create .exe file in the
same folder.
● Syntax to call .exe file in your
selenium script is:
Runtime.getRuntime().exec(“path of .exe
file”);
Pic. 1
<html>
<body>
<form>
<label id="choose-file-btn">Choose File</label>
</form>
</body>
</html>
Example : 2 (AutoIt)
ControlFocus("Open","","Edit1")
Sleep(3000)
ControlSetText("Open","","Edit1","C:UsersluciferProjectsRndassetsimage1.png")
Sleep(3000)
ControlClick("Open","","Button1")
Our AutoIt Script (save it as upload.au3):
Example : 2 (AutoIt)
There are lots of method available which we can use in an AutoIt script depending upon our
requirement. Here we will be only focusing on the following methods:
For other methods use official AutoIt link:
https://www.autoitscript.com/autoit3/docs/
1. ControlFocus(" title "," text ",”controlID” ) //Sets focus to a control.
2. ControlSetText(" title "," text ",”controlID” ," File path" ) // Sets text of a control.
3. ControlClick(" title "," text ",”controlID” ) //Sends a mouse click command to a control.
Note: One or more properties are used in the controlID parameter of a control command in the
format:
● Parameter values for first method (ControlFocus):
This method sets focus to the 'filename' text box of the file uploader window.
1st parameter, title is " Open ".
2nd parameter, the text is not required(We ignored).
3rd parameter, controlID is the combination of class='Edit' and Instance='1'
i.e., . 'Edit1.'
Example : 2 (AutoIt)
● Parameter values for second method (ControlSetText):
This method has one more attribute(new text) compare to previous one. This method is used
to define the path of a file which we need to upload in 'filename' textbox.
1st parameter, title is " Open ".
2nd parameter, the text is not required( We ignored).
3rd parameter, controlID is the combination of class and Instance, i.e., " Edit1 ".
4th parameter new text, in this we pass the path of the file which we want to upload.
● Parameter values for third method (ControlClick):
This method clicks on 'Open' button of the file uploader window.
1st parameter, title is " Open ".
2nd parameter; the text is not required (We ignored ).
3rd parameter, controlID is the combination of class and Instance, i.e., " Button1 ".
Example : 2 (AutoIt)
WebElement element = driver.findElement(By.name("choose-file-btn"));
element.click();
Runtime.getRuntime().exec("C:UsersluciferProjectsRndAutoItScriptsupload.exe");
Our Selenium Script
Runtime.getRuntime().exec(“path of .exe file”);
Syntax to call AutoIt script in selenium script:
Limitations of AutoIt:
1. It works only in Windows.
2. Knowledge of fundamental coding principles is a must.
Using Sikuli
Scripting
SikuliX automates anything you see on
the screen of your desktop computer
running Windows, Mac or some
Linux/Unix. It uses image recognition
powered by OpenCV to identify and
control GUI components. You can both
automate desktop or web applications
regardless of any technology. It is useful
when there is no easy access to a GUI’s
internal or source code.
How to begin with Sikuli
Similar to AutoIt, you will find lots of docs online for Sikuli setup also (especially for Windows). I am an
Ubuntu user so I will show you how to do the Sikuli setup on Ubuntu:
1. Install the JAVA
if you don't have java setup, do the following steps(here I am using Java 7):
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
java -version //to check your java version
2. Install OpenCV 2.4.0
sudo add-apt-repository ppa:gijzelaar/opencv2.4
sudo apt-get update
sudo apt-get libcv-dev
3. Install Tesseract 3
sudo apt-get install libtesseract3
How to begin with Sikuli
4. Packages for app-related features
sudo apt-get install wmctrl
sudo apt-get install xdotool
5. Download and launch sikulisetup-xxx.jar
Use following link to download sikulisetup-xxx.jar
https://launchpad.net/sikuli/sikulix/
mkdir ~/SikuliX
After downloading sikulisetup-xxx.jar move it to ~/SikuliX.
cd ~/SikuliX && java -jar sikuli-setup-xxx.jar
After this, you will get GUI option for installation and when you are done with installation do to
SikuliX. Configure SIKULI JAR - Create SIKULIX_HOME environment variable and set the path
of the Sikuli jar file (in ~/.bashrc file).
6. Launch the Sikuli IDE.
After successful installation, you will see runsikulix file in SikuliX folder.
cd ~/SikuliX
./runsikulix // This will launch Sikuli IDE.
Use Sikuli in Selenium Script
Supported scripting languages:
Python (language level 2.7) supported by the Jython interpreter.
Ruby (language level 1.9/2.0) supported by the JRuby interpreter.
JavaScript supported by the Java builtin scripting engine (Java 7: Rhino, Java 8: Nashorn).
I will be using JRuby for my selenium script.
1. We need to make sure we are have JRuby
rvm list // This is will show installed ruby version including JRuby (if it is installed)
sudo apt-get update
sudo apt-get install jruby // To install JRuby
rvm list // Now you should see JRuby (Mine is jruby-9.1.6.0)
rvm use jruby-9.1.6.0 // to use JRuby
2. Require sikuli in .rb file
require 'sikuli' // add this in your code
3. Create a folder for Sikuli images in your project:
Put all your Sikuli images(images that will be used by script) over here.
4. Then Run your selenium script.
<html>
<body>
<form>
<label id="choose-file-btn">Choose File</label>
</form>
</body>
</html>
Example : 3 (Sikuli)
find('#choose-file-btn').click
screen = Sikuli::Screen.new
screen.click "./features/images/desktop.png"
screen.click "./features/images/location.png"
screen.type "/home/lucifer/projects/rnd/features/images/vai.png"
screen.click "./features/images/open-button.png"
find('.save-modal-button').click
Our Selenium Script
Example : 3 (Sikuli)
Similarly to AutoIt, Sikuli has lots of methods available which we can use in a Selenium script
depending upon our requirement. Here we will be only focusing on the following methods:
For other methods use following link:
http://www.rubydoc.info/gems/sikuli/0.1.7/Sikuli
1. screen = Sikuli::Screen.new
2. screen.click
3. screen.type
● screen = Sikuli::Screen.new: The “Screen” is a base class provided by Sikuli. In order to
access all the Sikuli methods first, we have to create an Object for the Screen class (Base
class).
● Parameter value for first method (click):
This method will perform a single click on an image match, whose path we need to pass as a
parameter.
1st parameter, path of the image (absolute or relative path.)
i.e., . './features/images/desktop.png'
Or
'/home/lucifer/rnd/features/images/desktop.png'
Example : 3 (Sikuli)
● Parameter value for method (type):
This method will Types text as if it was being typed on the keyboard with an optional key
modifier.
1st parameter, ”text”
e.g, . 'Hello world'
Limitation of Sikuli
1. Accuracy of image matching is not 100%. It is possible that two or more similar images are
available on the screen, Sikuli will attempt to select the wrong image.
2. If image appearance varies in pixel size, then the script will fail with
“(Sikuli::ImageNotFound)” error.
3. Overhead of taking too many screenshots (depends upon requirement).
Thank You
Pankaj Biswas

Contenu connexe

Tendances

Exception handling
Exception handlingException handling
Exception handlingAnna Pietras
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Selenium locators: ID, Name,  xpath, CSS Selector advance methodsSelenium locators: ID, Name,  xpath, CSS Selector advance methods
Selenium locators: ID, Name, xpath, CSS Selector advance methodsPankaj Dubey
 
What is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | EdurekaWhat is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | EdurekaEdureka!
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and AnswersPython Devloper
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Simplilearn
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.pptAna Sarbescu
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Boxing & unboxing
Boxing & unboxingBoxing & unboxing
Boxing & unboxingLarry Nung
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response StructureBhagyashreeGajera1
 
Hướng dẫn sử dụng Selenium ide
Hướng dẫn sử dụng Selenium ideHướng dẫn sử dụng Selenium ide
Hướng dẫn sử dụng Selenium ideThiện Dương
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation xShahjahan Samoon
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKEAbhishek Yadav
 

Tendances (20)

Selenium
SeleniumSelenium
Selenium
 
Exception handling
Exception handlingException handling
Exception handling
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Selenium locators: ID, Name,  xpath, CSS Selector advance methodsSelenium locators: ID, Name,  xpath, CSS Selector advance methods
Selenium locators: ID, Name, xpath, CSS Selector advance methods
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
testng
testngtestng
testng
 
What is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | EdurekaWhat is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | Edureka
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and Answers
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
 
XXE
XXEXXE
XXE
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.ppt
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Java Method, Static Block
Java Method, Static BlockJava Method, Static Block
Java Method, Static Block
 
Boxing & unboxing
Boxing & unboxingBoxing & unboxing
Boxing & unboxing
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
SELENIUM PPT.pdf
SELENIUM PPT.pdfSELENIUM PPT.pdf
SELENIUM PPT.pdf
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Hướng dẫn sử dụng Selenium ide
Hướng dẫn sử dụng Selenium ideHướng dẫn sử dụng Selenium ide
Hướng dẫn sử dụng Selenium ide
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
 

Similaire à Uploading files using selenium web driver

Selenium with testng and eclipse ide
Selenium with testng and eclipse ideSelenium with testng and eclipse ide
Selenium with testng and eclipse ideTestertester Jaipur
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appiumPratik Patel
 
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)Tech OneStop
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotTsai Tsung-Yi
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntukesavan N B
 
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Rashedul Islam
 
Django simplified : by weever mbakaya
Django simplified : by weever mbakayaDjango simplified : by weever mbakaya
Django simplified : by weever mbakayaMbakaya Kwatukha
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slidesDavid Barreto
 
How to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_frameworkHow to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_frameworkHarshad Ingle
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersProtractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersHaitham Refaat
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkRapidValue
 
UI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricksUI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricksTsimafei Avilin
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTreeThe Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTreeRedBlackTree
 

Similaire à Uploading files using selenium web driver (20)

Selenium with testng and eclipse ide
Selenium with testng and eclipse ideSelenium with testng and eclipse ide
Selenium with testng and eclipse ide
 
Selenium.pptx
Selenium.pptxSelenium.pptx
Selenium.pptx
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntu
 
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
Step 8_7_ 6_5_4_3_2_ 1 in one_Tutorial for Begineer on Selenium Web Driver-Te...
 
Django simplified : by weever mbakaya
Django simplified : by weever mbakayaDjango simplified : by weever mbakaya
Django simplified : by weever mbakaya
 
Spring boot
Spring bootSpring boot
Spring boot
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
How to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_frameworkHow to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_framework
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine ReportersProtractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine Reporters
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
UI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricksUI Automation_White_CodedUI common problems and tricks
UI Automation_White_CodedUI common problems and tricks
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Django Deployment
Django DeploymentDjango Deployment
Django Deployment
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
Selenium
SeleniumSelenium
Selenium
 
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTreeThe Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
The Mobile ToolChain with Fastlane - Code Red Talk at RedBlackTree
 
Selenium Training in Chennai
Selenium Training in ChennaiSelenium Training in Chennai
Selenium Training in Chennai
 

Dernier

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 

Dernier (20)

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 

Uploading files using selenium web driver

  • 2. Uploading File Uploading a file is a basic piece of functionality found in the web applications. Automating these sorts of functionality is tricky in Selenium as Selenium is limited to automating browsers only, so when you are trying to automate it you get prompted with a dialog box that is just out of reach for Selenium. If "Upload button" is an Input Tag then uploading a file is easy, you can simply use SENDKEYS method. But if it is not an Input Tag and you are looking to automate it then you need third party tools.
  • 3. Ways to Upload File 1. Using SendKeys method. 2. Using AutoIt scripting. 3. Using Sikuli scripting.
  • 4. Using SendKeys Method sendKeys method is basically used to type some content into an input field/tag. The most basic way to perform the upload of a file. Simply, get the file upload element by using any locator you want. And call the sendKeys() method to set the value of the file to upload, the value can be the absolute or relative path of the file. Limitation This only works for INPUT tags.
  • 5. <html> <body> <form> Upload Your CV: <input type="file" name="uploadfile" id="upfile"> </form> </body> </html> driver.findElement(By.id("upfile")).sendKeys("C:filepathToUpload.txt"); The file path could be either absolute or relative file path. Example : 1 (sendKeys)
  • 6. Using AutoIt Scripting If you have a button (Customized button), not an input tag and when clicking on the browse button, the browser opens a window popup and to select the file from system, And as we know selenium will not support OS controls. Here we need third party tool like AutoIt. AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate web app and desktop app.
  • 7. How to begin with AutoIt AutoIt setup is easy, there are lots of docs available on online for this. Basically, we need following two things to be installed, to begin with. 1. Install AutoIt current version. Go for AutoIt Full Installation, this will provide a basic version of the SciTE script editor. To get full version of you have to download it separately. https://www.autoitscript.com/site/autoit/downloads/ 2. AutoIt Script Editor (Download the SciTE.exe and install; it is an editor which helps in finding the commands.).
  • 8. How to Write AutoIt Script ● Identify the Windows control, through AutoIt Windows Info tool (See Pic. 1). ● Click on Finder Tool and hover over the object for which you want the properties. ● It will capture the properties of pop up like Title, Class, Position, Size, Style and so on. ● Then with the help of captured properties, write a script in SciTE script editor or in sublime and save the script with .au3 extension
  • 9. How to Write AutoIt Script ● Now to compile the .au3 script you can either use AutoIt Script to EXE converter, which converts .au3 file to .exe file or just right click your .au3 script, it will show compile options. Select compile to 64bit (x64) or compile to 32bit (x86) option and will create .exe file in the same folder. ● Syntax to call .exe file in your selenium script is: Runtime.getRuntime().exec(“path of .exe file”); Pic. 1
  • 10. <html> <body> <form> <label id="choose-file-btn">Choose File</label> </form> </body> </html> Example : 2 (AutoIt) ControlFocus("Open","","Edit1") Sleep(3000) ControlSetText("Open","","Edit1","C:UsersluciferProjectsRndassetsimage1.png") Sleep(3000) ControlClick("Open","","Button1") Our AutoIt Script (save it as upload.au3):
  • 11. Example : 2 (AutoIt) There are lots of method available which we can use in an AutoIt script depending upon our requirement. Here we will be only focusing on the following methods: For other methods use official AutoIt link: https://www.autoitscript.com/autoit3/docs/ 1. ControlFocus(" title "," text ",”controlID” ) //Sets focus to a control. 2. ControlSetText(" title "," text ",”controlID” ," File path" ) // Sets text of a control. 3. ControlClick(" title "," text ",”controlID” ) //Sends a mouse click command to a control. Note: One or more properties are used in the controlID parameter of a control command in the format: ● Parameter values for first method (ControlFocus): This method sets focus to the 'filename' text box of the file uploader window. 1st parameter, title is " Open ". 2nd parameter, the text is not required(We ignored). 3rd parameter, controlID is the combination of class='Edit' and Instance='1' i.e., . 'Edit1.'
  • 12. Example : 2 (AutoIt) ● Parameter values for second method (ControlSetText): This method has one more attribute(new text) compare to previous one. This method is used to define the path of a file which we need to upload in 'filename' textbox. 1st parameter, title is " Open ". 2nd parameter, the text is not required( We ignored). 3rd parameter, controlID is the combination of class and Instance, i.e., " Edit1 ". 4th parameter new text, in this we pass the path of the file which we want to upload. ● Parameter values for third method (ControlClick): This method clicks on 'Open' button of the file uploader window. 1st parameter, title is " Open ". 2nd parameter; the text is not required (We ignored ). 3rd parameter, controlID is the combination of class and Instance, i.e., " Button1 ".
  • 13. Example : 2 (AutoIt) WebElement element = driver.findElement(By.name("choose-file-btn")); element.click(); Runtime.getRuntime().exec("C:UsersluciferProjectsRndAutoItScriptsupload.exe"); Our Selenium Script Runtime.getRuntime().exec(“path of .exe file”); Syntax to call AutoIt script in selenium script: Limitations of AutoIt: 1. It works only in Windows. 2. Knowledge of fundamental coding principles is a must.
  • 14. Using Sikuli Scripting SikuliX automates anything you see on the screen of your desktop computer running Windows, Mac or some Linux/Unix. It uses image recognition powered by OpenCV to identify and control GUI components. You can both automate desktop or web applications regardless of any technology. It is useful when there is no easy access to a GUI’s internal or source code.
  • 15. How to begin with Sikuli Similar to AutoIt, you will find lots of docs online for Sikuli setup also (especially for Windows). I am an Ubuntu user so I will show you how to do the Sikuli setup on Ubuntu: 1. Install the JAVA if you don't have java setup, do the following steps(here I am using Java 7): sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-installer java -version //to check your java version 2. Install OpenCV 2.4.0 sudo add-apt-repository ppa:gijzelaar/opencv2.4 sudo apt-get update sudo apt-get libcv-dev 3. Install Tesseract 3 sudo apt-get install libtesseract3
  • 16. How to begin with Sikuli 4. Packages for app-related features sudo apt-get install wmctrl sudo apt-get install xdotool 5. Download and launch sikulisetup-xxx.jar Use following link to download sikulisetup-xxx.jar https://launchpad.net/sikuli/sikulix/ mkdir ~/SikuliX After downloading sikulisetup-xxx.jar move it to ~/SikuliX. cd ~/SikuliX && java -jar sikuli-setup-xxx.jar After this, you will get GUI option for installation and when you are done with installation do to SikuliX. Configure SIKULI JAR - Create SIKULIX_HOME environment variable and set the path of the Sikuli jar file (in ~/.bashrc file). 6. Launch the Sikuli IDE. After successful installation, you will see runsikulix file in SikuliX folder. cd ~/SikuliX ./runsikulix // This will launch Sikuli IDE.
  • 17. Use Sikuli in Selenium Script Supported scripting languages: Python (language level 2.7) supported by the Jython interpreter. Ruby (language level 1.9/2.0) supported by the JRuby interpreter. JavaScript supported by the Java builtin scripting engine (Java 7: Rhino, Java 8: Nashorn). I will be using JRuby for my selenium script. 1. We need to make sure we are have JRuby rvm list // This is will show installed ruby version including JRuby (if it is installed) sudo apt-get update sudo apt-get install jruby // To install JRuby rvm list // Now you should see JRuby (Mine is jruby-9.1.6.0) rvm use jruby-9.1.6.0 // to use JRuby 2. Require sikuli in .rb file require 'sikuli' // add this in your code 3. Create a folder for Sikuli images in your project: Put all your Sikuli images(images that will be used by script) over here. 4. Then Run your selenium script.
  • 18. <html> <body> <form> <label id="choose-file-btn">Choose File</label> </form> </body> </html> Example : 3 (Sikuli) find('#choose-file-btn').click screen = Sikuli::Screen.new screen.click "./features/images/desktop.png" screen.click "./features/images/location.png" screen.type "/home/lucifer/projects/rnd/features/images/vai.png" screen.click "./features/images/open-button.png" find('.save-modal-button').click Our Selenium Script
  • 19. Example : 3 (Sikuli) Similarly to AutoIt, Sikuli has lots of methods available which we can use in a Selenium script depending upon our requirement. Here we will be only focusing on the following methods: For other methods use following link: http://www.rubydoc.info/gems/sikuli/0.1.7/Sikuli 1. screen = Sikuli::Screen.new 2. screen.click 3. screen.type ● screen = Sikuli::Screen.new: The “Screen” is a base class provided by Sikuli. In order to access all the Sikuli methods first, we have to create an Object for the Screen class (Base class). ● Parameter value for first method (click): This method will perform a single click on an image match, whose path we need to pass as a parameter. 1st parameter, path of the image (absolute or relative path.) i.e., . './features/images/desktop.png' Or '/home/lucifer/rnd/features/images/desktop.png'
  • 20. Example : 3 (Sikuli) ● Parameter value for method (type): This method will Types text as if it was being typed on the keyboard with an optional key modifier. 1st parameter, ”text” e.g, . 'Hello world' Limitation of Sikuli 1. Accuracy of image matching is not 100%. It is possible that two or more similar images are available on the screen, Sikuli will attempt to select the wrong image. 2. If image appearance varies in pixel size, then the script will fail with “(Sikuli::ImageNotFound)” error. 3. Overhead of taking too many screenshots (depends upon requirement).