SlideShare a Scribd company logo
1 of 21
Selenium Webdriver
Fundamentals + Hands-
on!
by Miriam Marciel
September 2016
Web automatization
• Perform actions like a user would do
– Testing webpages
• Selenium:
• Selenium Webdriver: native browser
• Selenium Grid: tests in different servers
• Selenium IDE: recording of actions
Selenium Webdriver features
• Browsers:
– Firefox
– Chrome
– Internet Explorer
– Safari
– PhantomJS (headless browser)
• Languages:
– Java
– Python
– Javascript
– Ruby
– C#
• Customization of browser settings: addons, proxy, cookies…
Selenium installation
• Java
– Download *.jar/Maven
• Python
pip install selenium
• Javascript
npm install selenium-webdriver
• Ruby
gem install selenium-webdriver
Basics
• Import
from selenium import webdriver
• Open browser:
driver = webdriver.Firefox()
driver = webdriver.Chrome()
driver = webdriver.Safari()
• Page retrieving
driver.get("http://www.python.org")
This will stop the execution of the program until the webpage is
completely loaded
Finding elements
• Find element by id, name, class name,
tag name, xpath…
element = driver.find_element_by_id("id-search-field")
element = driver.find_element_by_class_name("search-field”)
element = driver.find_element_by_tag_name("input")
element = driver.find_element_by_xpath("//*[contains(text(),'ABC')]")
element = driver.find_element_by_name("q")
Forms (I)
• Textboxes
– element.send_keys("pycon")
• Select
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_tag_name("select"))
select.select_by_visible_text("Mercedes")
• Multiselect
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_id("select_multiple"))
select.deselect_all()
select.select_by_visible_text("Audi")
select.select_by_visible_text("Ferrari")
Forms (II)
• Checkboxes
driver.find_element_by_id("cbox1").click()
• Button
driver.find_element_by_id("submit").click()
Radio button: driver.find_element_by_id("radio2").click()
• Get text
element = driver.find_element_by_id("counter")
element.text
• Keys
from selenium.webdriver.common.keys import Keys
element.send_keys(Keys.RETURN)
element.send_keys(Keys.COMMAND, 'f')
Advance features (I)
• Moving between windows and iframes
– HTML: <a href="somewhere.html" target="windowName">Click here to
open a new window</a>
– Python: driver.switch_to.window("windowName")
• Dialogs
– alert = driver.switch_to.alert
– alert.dismiss()
• Navigation
– driver.forward()
– driver.back()
Browser settings (I)
• Cookies:
driver.add_cookie({'name':'key', 'value':'value', 'path':'/'})
driver.get_cookies() # Only first party cookies
driver.delete_cookie("CookieName")
driver.delete_all_cookies()
• User Agent
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", "some UA string")
driver = webdriver.Firefox(profile)
Browser settings (II)
• Proxy
proxy = Proxy({'httpProxy': myProxy})
driver = webdriver.Firefox(proxy=proxy)
• Firefox Binary
binary = FirefoxBinary("firefox-executable");
driver = webdriver.Firefox(firefox_binary=binary)
Browser settings (III)
• Plugins/Addons
profile = webdriver.FirefoxProfile()
profile.add_extension(extension=’path-to-xpi/ublock.xpi')
driver_addon = webdriver.Firefox(firefox_profile=profile)
• about:config options of Firefox
profile = webdriver.FirefoxProfile()
profile.set_preference("javascript.enabled", False);
driver = webdriver.Firefox(firefox_profile=profile)
Closing the browser
• There are two functions:
driver.quit()
driver.close()
• The difference is if the profile folder is deleted or not
– quit: deletes the folder
– close: doesn’t delete the folder
• Profile folder has a name starting with tmp and some
random characters
• Location of the folder
– Mac: /private/var and one random subfolder
– Linux: /tmp/
• You can also check the profile folder in about:support in
the Firefox of Selenium
Waits
• What happens when you click an element
and it is not present or hidden? =>
Exception!!
• To solve this problems, there are two kinds
of waits: implicit and explicit
– Implicit wait: maximum time to wait for elements
to be present in the DOM
– Explicit wait + expected condition: maximum
time to wait for elements to be present and
condition is true
Explicit wait conditions
• title_is
• title_contains
• presence_of_element_located
• visibility_of_element_located
• visibility_of
• presence_of_all_elements_located
• text_to_be_present_in_element
• text_to_be_present_in_element_value
• frame_to_be_available_and_switch_to_it
• invisibility_of_element_located
• element_to_be_clickable
• staleness_of
• element_to_be_selected
• element_located_to_be_selected
• element_selection_state_to_be
• element_located_selection_state_to_be
• alert_is_present
Implicit and explicit waits
• Implicit wait:
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://some_url")
driver.find_element_by_id(”element").click() # Will wait for 10s until the element is present
• Explicit wait
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get(”http://some_url")
element = wait.until(EC.element_to_be_clickable((By.ID,’some_element')))
No GUI
• When working without GUI is important to set the
window size/resolution, as webpages may not be
displayed properly
• PhantomJS
driver = webdriver.PhantomJS()
driver.set_window_size(1400,1000)
• Ubuntu
– Install xvfb: apt-get install xvfb
– Package for python: pip install pyvirtualdisplay
– File:
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
…
display.stop()
DEMO
Conclusion: advices using Selenium
• Launch always the same version of browser with
FirefoxBinary
• When finding elements, use WebDriverWait to check that
the element complies with the action you want to
perform
• Selection of ids: not choose random ids
• Working without GUI: set resolution as big as
possible
Conclusion: advices using Selenium
• Timers: sometimes webpages are not loaded
properly and the browser gets stuck. In order to
solve this, you can set preferences in Firefox:
driver.set_page_load_timeout(10)
driver.set_script_timeout(10)
profile.set_preference(“network.http.response.timeout”, 10)
profile.set_preference(“dom.max_script_run_time”, 10)
profile.set_preference("network.http.connection-retry-timeout", 10);
SELENIUM WEBDRIVER:
FUNDAMENTALS + HANDS-ON!
Miriam Marciel
09/09/2016
21

More Related Content

Viewers also liked

Video Transcoding with Raspberry Pi
Video Transcoding with Raspberry PiVideo Transcoding with Raspberry Pi
Video Transcoding with Raspberry PiAlfonso Peletier
 
NSO Esprit scholen | training ICT in het onderwijs | management
NSO Esprit scholen | training ICT in het onderwijs | managementNSO Esprit scholen | training ICT in het onderwijs | management
NSO Esprit scholen | training ICT in het onderwijs | managementHenk Orsel
 
CHANDRASHEKAR RESUME (1) (3)
CHANDRASHEKAR RESUME (1) (3)CHANDRASHEKAR RESUME (1) (3)
CHANDRASHEKAR RESUME (1) (3)Chandra Shekar
 
positief denken intro
positief denken intropositief denken intro
positief denken introAlice Rosema
 
MarketingCamp2012 Art of Social Media
MarketingCamp2012 Art of Social MediaMarketingCamp2012 Art of Social Media
MarketingCamp2012 Art of Social MediaSocial Strand Media
 
Dagli alias allo spid (ita)
Dagli alias allo spid (ita)Dagli alias allo spid (ita)
Dagli alias allo spid (ita)Raffaele Poli
 
Enterprise applications, Web & Analytics trends 2012
Enterprise applications, Web & Analytics trends 2012Enterprise applications, Web & Analytics trends 2012
Enterprise applications, Web & Analytics trends 2012Einat Shimoni
 
systemisch werken intro
systemisch werken introsystemisch werken intro
systemisch werken introAlice Rosema
 
Paris Video Tech #2 - Presentation by Jean-Yves Avenard
Paris Video Tech #2 - Presentation by Jean-Yves AvenardParis Video Tech #2 - Presentation by Jean-Yves Avenard
Paris Video Tech #2 - Presentation by Jean-Yves AvenardErica Beavers
 
Spouses of H-1B Workers Can Now Seek Employment
Spouses of H-1B Workers Can Now Seek EmploymentSpouses of H-1B Workers Can Now Seek Employment
Spouses of H-1B Workers Can Now Seek EmploymentThe Shapiro Law Group
 

Viewers also liked (18)

Video Transcoding with Raspberry Pi
Video Transcoding with Raspberry PiVideo Transcoding with Raspberry Pi
Video Transcoding with Raspberry Pi
 
Understanding open max il
Understanding open max ilUnderstanding open max il
Understanding open max il
 
NSO Esprit scholen | training ICT in het onderwijs | management
NSO Esprit scholen | training ICT in het onderwijs | managementNSO Esprit scholen | training ICT in het onderwijs | management
NSO Esprit scholen | training ICT in het onderwijs | management
 
TechFugees Italy
TechFugees ItalyTechFugees Italy
TechFugees Italy
 
CHANDRASHEKAR RESUME (1) (3)
CHANDRASHEKAR RESUME (1) (3)CHANDRASHEKAR RESUME (1) (3)
CHANDRASHEKAR RESUME (1) (3)
 
La internet.
La internet.La internet.
La internet.
 
positief denken intro
positief denken intropositief denken intro
positief denken intro
 
MarketingCamp2012 Art of Social Media
MarketingCamp2012 Art of Social MediaMarketingCamp2012 Art of Social Media
MarketingCamp2012 Art of Social Media
 
Modelo educativo DGCFT
Modelo educativo DGCFTModelo educativo DGCFT
Modelo educativo DGCFT
 
Dagli alias allo spid (ita)
Dagli alias allo spid (ita)Dagli alias allo spid (ita)
Dagli alias allo spid (ita)
 
Enterprise applications, Web & Analytics trends 2012
Enterprise applications, Web & Analytics trends 2012Enterprise applications, Web & Analytics trends 2012
Enterprise applications, Web & Analytics trends 2012
 
systemisch werken intro
systemisch werken introsystemisch werken intro
systemisch werken intro
 
Seminar design pattern
Seminar design patternSeminar design pattern
Seminar design pattern
 
ICE basic
ICE basicICE basic
ICE basic
 
Paris Video Tech #2 - Presentation by Jean-Yves Avenard
Paris Video Tech #2 - Presentation by Jean-Yves AvenardParis Video Tech #2 - Presentation by Jean-Yves Avenard
Paris Video Tech #2 - Presentation by Jean-Yves Avenard
 
AI and Udacity
AI and UdacityAI and Udacity
AI and Udacity
 
Ready for Funding?
Ready for Funding?Ready for Funding?
Ready for Funding?
 
Spouses of H-1B Workers Can Now Seek Employment
Spouses of H-1B Workers Can Now Seek EmploymentSpouses of H-1B Workers Can Now Seek Employment
Spouses of H-1B Workers Can Now Seek Employment
 

Similar to 2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on!

Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaEr. Sndp Srda
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Sauce Labs
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
Selenium rc ppt
Selenium rc pptSelenium rc ppt
Selenium rc pptmindqqa
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013Tim Plummer
 
Selenium Online Training
Selenium  Online TrainingSelenium  Online Training
Selenium Online TrainingLearntek1
 
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016Chris Gates
 
Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with JavaFayis-QA
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engineth0masr
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Selenium training
Selenium trainingSelenium training
Selenium trainingShivaraj R
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdffull-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdfBrian Takita
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 

Similar to 2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on! (20)

Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Selenium rc ppt
Selenium rc pptSelenium rc ppt
Selenium rc ppt
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013
 
Selenium Online Training
Selenium  Online TrainingSelenium  Online Training
Selenium Online Training
 
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016DevOops Redux Ken Johnson Chris Gates  - AppSec USA 2016
DevOops Redux Ken Johnson Chris Gates - AppSec USA 2016
 
Browser-level testing
Browser-level testingBrowser-level testing
Browser-level testing
 
Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with Java
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engine
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdffull-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
iOS Application Pentesting
iOS Application PentestingiOS Application Pentesting
iOS Application Pentesting
 
Maven
MavenMaven
Maven
 

Recently uploaded

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 

Recently uploaded (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on!

  • 1. Selenium Webdriver Fundamentals + Hands- on! by Miriam Marciel September 2016
  • 2. Web automatization • Perform actions like a user would do – Testing webpages • Selenium: • Selenium Webdriver: native browser • Selenium Grid: tests in different servers • Selenium IDE: recording of actions
  • 3. Selenium Webdriver features • Browsers: – Firefox – Chrome – Internet Explorer – Safari – PhantomJS (headless browser) • Languages: – Java – Python – Javascript – Ruby – C# • Customization of browser settings: addons, proxy, cookies…
  • 4. Selenium installation • Java – Download *.jar/Maven • Python pip install selenium • Javascript npm install selenium-webdriver • Ruby gem install selenium-webdriver
  • 5. Basics • Import from selenium import webdriver • Open browser: driver = webdriver.Firefox() driver = webdriver.Chrome() driver = webdriver.Safari() • Page retrieving driver.get("http://www.python.org") This will stop the execution of the program until the webpage is completely loaded
  • 6. Finding elements • Find element by id, name, class name, tag name, xpath… element = driver.find_element_by_id("id-search-field") element = driver.find_element_by_class_name("search-field”) element = driver.find_element_by_tag_name("input") element = driver.find_element_by_xpath("//*[contains(text(),'ABC')]") element = driver.find_element_by_name("q")
  • 7. Forms (I) • Textboxes – element.send_keys("pycon") • Select from selenium.webdriver.support.ui import Select select = Select(driver.find_element_by_tag_name("select")) select.select_by_visible_text("Mercedes") • Multiselect from selenium.webdriver.support.ui import Select select = Select(driver.find_element_by_id("select_multiple")) select.deselect_all() select.select_by_visible_text("Audi") select.select_by_visible_text("Ferrari")
  • 8. Forms (II) • Checkboxes driver.find_element_by_id("cbox1").click() • Button driver.find_element_by_id("submit").click() Radio button: driver.find_element_by_id("radio2").click() • Get text element = driver.find_element_by_id("counter") element.text • Keys from selenium.webdriver.common.keys import Keys element.send_keys(Keys.RETURN) element.send_keys(Keys.COMMAND, 'f')
  • 9. Advance features (I) • Moving between windows and iframes – HTML: <a href="somewhere.html" target="windowName">Click here to open a new window</a> – Python: driver.switch_to.window("windowName") • Dialogs – alert = driver.switch_to.alert – alert.dismiss() • Navigation – driver.forward() – driver.back()
  • 10. Browser settings (I) • Cookies: driver.add_cookie({'name':'key', 'value':'value', 'path':'/'}) driver.get_cookies() # Only first party cookies driver.delete_cookie("CookieName") driver.delete_all_cookies() • User Agent profile = webdriver.FirefoxProfile() profile.set_preference("general.useragent.override", "some UA string") driver = webdriver.Firefox(profile)
  • 11. Browser settings (II) • Proxy proxy = Proxy({'httpProxy': myProxy}) driver = webdriver.Firefox(proxy=proxy) • Firefox Binary binary = FirefoxBinary("firefox-executable"); driver = webdriver.Firefox(firefox_binary=binary)
  • 12. Browser settings (III) • Plugins/Addons profile = webdriver.FirefoxProfile() profile.add_extension(extension=’path-to-xpi/ublock.xpi') driver_addon = webdriver.Firefox(firefox_profile=profile) • about:config options of Firefox profile = webdriver.FirefoxProfile() profile.set_preference("javascript.enabled", False); driver = webdriver.Firefox(firefox_profile=profile)
  • 13. Closing the browser • There are two functions: driver.quit() driver.close() • The difference is if the profile folder is deleted or not – quit: deletes the folder – close: doesn’t delete the folder • Profile folder has a name starting with tmp and some random characters • Location of the folder – Mac: /private/var and one random subfolder – Linux: /tmp/ • You can also check the profile folder in about:support in the Firefox of Selenium
  • 14. Waits • What happens when you click an element and it is not present or hidden? => Exception!! • To solve this problems, there are two kinds of waits: implicit and explicit – Implicit wait: maximum time to wait for elements to be present in the DOM – Explicit wait + expected condition: maximum time to wait for elements to be present and condition is true
  • 15. Explicit wait conditions • title_is • title_contains • presence_of_element_located • visibility_of_element_located • visibility_of • presence_of_all_elements_located • text_to_be_present_in_element • text_to_be_present_in_element_value • frame_to_be_available_and_switch_to_it • invisibility_of_element_located • element_to_be_clickable • staleness_of • element_to_be_selected • element_located_to_be_selected • element_selection_state_to_be • element_located_selection_state_to_be • alert_is_present
  • 16. Implicit and explicit waits • Implicit wait: driver = webdriver.Firefox() driver.implicitly_wait(10) driver.get("http://some_url") driver.find_element_by_id(”element").click() # Will wait for 10s until the element is present • Explicit wait driver = webdriver.Firefox() wait = WebDriverWait(driver, 10) driver.get(”http://some_url") element = wait.until(EC.element_to_be_clickable((By.ID,’some_element')))
  • 17. No GUI • When working without GUI is important to set the window size/resolution, as webpages may not be displayed properly • PhantomJS driver = webdriver.PhantomJS() driver.set_window_size(1400,1000) • Ubuntu – Install xvfb: apt-get install xvfb – Package for python: pip install pyvirtualdisplay – File: from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 600)) display.start() … display.stop()
  • 18. DEMO
  • 19. Conclusion: advices using Selenium • Launch always the same version of browser with FirefoxBinary • When finding elements, use WebDriverWait to check that the element complies with the action you want to perform • Selection of ids: not choose random ids • Working without GUI: set resolution as big as possible
  • 20. Conclusion: advices using Selenium • Timers: sometimes webpages are not loaded properly and the browser gets stuck. In order to solve this, you can set preferences in Firefox: driver.set_page_load_timeout(10) driver.set_script_timeout(10) profile.set_preference(“network.http.response.timeout”, 10) profile.set_preference(“dom.max_script_run_time”, 10) profile.set_preference("network.http.connection-retry-timeout", 10);
  • 21. SELENIUM WEBDRIVER: FUNDAMENTALS + HANDS-ON! Miriam Marciel 09/09/2016 21