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

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 

Recently uploaded (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

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