SlideShare a Scribd company logo
1 of 21
An Doan
Portland Selenium Users Group
                July 19th, 2012
   Problem: I have some javascript or AJAX that
    runs after the DOM is loaded.
   Solution: User WebDriverWait

    ◦ Repeats a function until one of the following
      conditions are met

        the   function returns neither null nor false
        the   function throws an unignored exception
        the   timeout expires
        the   current thread is interrupted
WebDriverWait wait = new WebDriverWait(driver, timeoutsec);
    WebElement element = Wait.until(myCondition);

          ExpectedCondition<WebElement> myCondition = new ExpectedCondition<WebElement>()
          {
                public WebElement apply(WebDriver d)
                {
                           return d.findElement(By.id(“someid"));
                }
          }


    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));


titleIs         frameToBeAvailableAndSwitchToIt   PresenseOfElement          visibilityOfElement

visibilityOf    presenceOfAllElementsLocatedBy    textToBePresentInElement   textToBePresentInElementByValue

titleContains   invisibilityOfElementLocated      elementToBeClickable       elementToBeSelected

stalenessOf     elementSelectionStateToBe         elementToBeSelected        elementSelectionStateToBe
   Problem: My test environment or test case
     requires me to edit some cookies or create
     new cookies.
    Solution:
     driver.manage.getCookieNamed(cookieName)
     driver.manage.addCookie(cookie)

myDriver.manage().getCookieNamed(“sesssionID”);

Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure);
myDriver.manage().addCookie(cookie);
   Problem: I just clicked on a link and it opened
    a new window, now what?
   Solution: Switch to the window using
    driver.switchTo.window(“windowHandle”)

    ◦ Iterate through all window handles to find the new
      window, wither by title or url
    ◦ Switch to the window using the window handle
public String switchToWindow(String title)
{
try
{
         if (prevWindow == null || prevWindow != title)
         {
                   prevWindow = myDriver.getTitle();
                   prevWindowHandle = myDriver.getWindowHandle();
                   myLog.logTcStep("Saved Prev Window Title:" + prevWindow);
         }
         myLog.logTcStep("Switching To Window Title:" + title);
         return getHandleByTitle(title);
} catch (Exception e) {
}
return null;
}
private String getHandleByTitle(String title)
{
String currentHandle = myDriver.getWindowHandle();
for (String handle : myDriver.getWindowHandles())
{
          if (title.equals(myDriver.switchTo().window (handle).getTitle()))
          {
          myLog.logStep("Found new window handle by title: " + handle);
          return handle;
          }
}
myLog.logStep("Could not find new window handle by title");
return currentHandle;
}
private String getHandleByUrl(String url)
{
String currentHandle = myDriver.getWindowHandle();
         for (String handle : myDriver.getWindowHandles())
         {
         if ((myDriver.switchTo().window (handle).getCurrentUrl()).contains(url))
         {
                   return handle;
         }
         }
return currentHandle;
}
   Problem: When I click on a link it opens a
    popup window, how do I close it when I am
    done validating it?
   Solution: Use window handles and
    driver.switchTo().window().close()

    ◦ Iterate through the window handles
    ◦ Close everything else but the main window
String currentWindow = myDriver.getWindowHandle();
Set<String> windows = myDriver.getWindowHandles();
for (Iterator<String> iterator = windows.iterator(); iterator.hasNext();)
{
          String string = (String) iterator.next();
          if (!currentWindow.equals(string))
          {
                     myDriver.switchTo().window(string).close();
                     myDriver.switchTo().window(currentWindow);
                     Util.sleep(1000);
                     return true;
          }
}
return false;
 Problem: The developer for my application
  likes to use a lot of iframes and Selenium
  doesn’t seem to work.
 Solution: Use
driver.switchTo().frame(iFrameName)
driver.switchTo().frame(iFrameIndex)

    ◦ Switches context to the frame
    ◦ Return to default context with
      myDriver.switchTo().defaultContent();
List<WebElement> elements = myDriver.findElements(By.tagName("iframe"));
if (elements != null)
         iframes = elements.size();



for (int f = 0; f < iframes ; f++)
{
myDriver.switchTo().frame(f);
          try
          {
                    element = myDriver.findElement(locator);
                    return element;
          }catch (Exception e) {}
}
return null;
   Problem: I need to hover over and menu and
    then click a submenu
   Solution: Use the Action class

hoverOverElement = waitForAndGetElement (locatorForHover);
Actions action = new Actions(myDriver);
action =
       action.moveToElement(hoverOverElement).
       moveToElement(waitForAndGetElement(locatorForClick)).
       click();
action.perform();
keyDown        click
keyUp          doubleClick
sendKeys       moveToElement
clickAndHold   moveByOffset
release        contextClick
dragAndDrop
   Problem: An alert window appears and blocks
    the automation.
   Solution: Use the Alert class (works most of
    the time)
try{
       Alert alert = myDriver.switchTo().alert();
       // And acknowledge the alert (equivalent to clicking "OK")
       alert.accept(); //OK
       alert.dismiss(); //”X”
       alert.sendKeys(Keys.ENTER); //Hit Enter on keyboard
       myLog.logTcStep("Closing Alert");
       return true;
} catch (Exception e) {
       // no alert
       myLog.logTcStep("Cannot Close Alert");
       e.printStackTrace();
       return false;
}
   Problem: AndroidDriver does not support
    Select, the native spinner pops up
   Solution: Use Javascript injection
WebElement select = getElement(locator);
List<WebElement> options = select.findElements(By.tagName("option"));
int optionNum = 0;
for(WebElement option : options){
         if(option.getText().equals(selection)) {
         try {
                   ((JavascriptExecutor) myDriver).executeScript
                   ("document.getElementById("newLocationSource").options["+
                   optionNum + "].selected = true");
                   Util.sleep(2000);
                   return true;
         } catch (Exception e) {}
         break;
         }
optionNum++;
}
   Events not firing?

//send enter key to select box
select. sendKeys(Keys.ENTER)

//dismiss the native spinner
Runtime.getRuntime().exec
("cmd.exe /K "+ env.get("ANDROID_HOME") + “
/platform-tools/adb shell input keyevent 66"); //key enter
   Aug. 16th
    ◦ Open
   Sept. 13th (Moved from the 20th)
    ◦ Lee Copeland – Topic TBD


Thank You Sponsors!

More Related Content

What's hot

Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsPeter-Paul Koch
 
Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019UA Mobile
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginnersIsfand yar Khan
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom eventBunlong Van
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android ArchitectureEric Maxwell
 
Easy undo.key
Easy undo.keyEasy undo.key
Easy undo.keyzachwaugh
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)Simon Su
 
AngularJS, More Than Directives !
AngularJS, More Than Directives !AngularJS, More Than Directives !
AngularJS, More Than Directives !Gaurav Behere
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data BindingEric Maxwell
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuerykolkatageeks
 

What's hot (19)

Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript Events
 
Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Deferred
DeferredDeferred
Deferred
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android Architecture
 
Easy undo.key
Easy undo.keyEasy undo.key
Easy undo.key
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
 
Blockly
BlocklyBlockly
Blockly
 
AngularJS, More Than Directives !
AngularJS, More Than Directives !AngularJS, More Than Directives !
AngularJS, More Than Directives !
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
Dojo1.0_Tutorials
Dojo1.0_TutorialsDojo1.0_Tutorials
Dojo1.0_Tutorials
 

Viewers also liked

Презентация ЗГМ. Система герметизации Абрис
Презентация ЗГМ. Система герметизации АбрисПрезентация ЗГМ. Система герметизации Абрис
Презентация ЗГМ. Система герметизации Абрисooozgm
 
Martin Petrášek, eMerite
Martin Petrášek, eMeriteMartin Petrášek, eMerite
Martin Petrášek, eMeriteTyinternety.cz
 
Tek Advertising & Management P. Ltd Profile
Tek Advertising & Management P. Ltd ProfileTek Advertising & Management P. Ltd Profile
Tek Advertising & Management P. Ltd ProfileAmit Singh
 

Viewers also liked (8)

proyecto josé pérez
proyecto josé pérezproyecto josé pérez
proyecto josé pérez
 
itw 04AR
itw 04ARitw 04AR
itw 04AR
 
2 4-5
2 4-52 4-5
2 4-5
 
MP Shining Star
MP Shining StarMP Shining Star
MP Shining Star
 
Consenso AR
Consenso ARConsenso AR
Consenso AR
 
Презентация ЗГМ. Система герметизации Абрис
Презентация ЗГМ. Система герметизации АбрисПрезентация ЗГМ. Система герметизации Абрис
Презентация ЗГМ. Система герметизации Абрис
 
Martin Petrášek, eMerite
Martin Petrášek, eMeriteMartin Petrášek, eMerite
Martin Petrášek, eMerite
 
Tek Advertising & Management P. Ltd Profile
Tek Advertising & Management P. Ltd ProfileTek Advertising & Management P. Ltd Profile
Tek Advertising & Management P. Ltd Profile
 

Similar to What the FUF?

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Component Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with SeleniumComponent Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with SeleniumRichard Olrichs
 
Gilt Groupe's Selenium 2 Conversion Challenges
Gilt Groupe's Selenium 2 Conversion ChallengesGilt Groupe's Selenium 2 Conversion Challenges
Gilt Groupe's Selenium 2 Conversion ChallengesSauce Labs
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo Ali Parmaksiz
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutDror Helper
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
Window object methods (timer related)
Window object methods (timer related)Window object methods (timer related)
Window object methods (timer related)Shivani Thakur Daxini
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesKaniska Mandal
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsМарія Русин
 

Similar to What the FUF? (20)

From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Prototype UI
Prototype UIPrototype UI
Prototype UI
 
Unit testing with mock libs
Unit testing with mock libsUnit testing with mock libs
Unit testing with mock libs
 
Web-First Design Patterns
Web-First Design PatternsWeb-First Design Patterns
Web-First Design Patterns
 
Automated Testing ADF with Selenium
Automated Testing ADF with SeleniumAutomated Testing ADF with Selenium
Automated Testing ADF with Selenium
 
Component Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with SeleniumComponent Based Unit Testing ADF with Selenium
Component Based Unit Testing ADF with Selenium
 
Java awt
Java awtJava awt
Java awt
 
Gilt Groupe's Selenium 2 Conversion Challenges
Gilt Groupe's Selenium 2 Conversion ChallengesGilt Groupe's Selenium 2 Conversion Challenges
Gilt Groupe's Selenium 2 Conversion Challenges
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you about
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Window object methods (timer related)
Window object methods (timer related)Window object methods (timer related)
Window object methods (timer related)
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax Applications
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

What the FUF?

  • 1. An Doan Portland Selenium Users Group July 19th, 2012
  • 2. Problem: I have some javascript or AJAX that runs after the DOM is loaded.  Solution: User WebDriverWait ◦ Repeats a function until one of the following conditions are met  the function returns neither null nor false  the function throws an unignored exception  the timeout expires  the current thread is interrupted
  • 3. WebDriverWait wait = new WebDriverWait(driver, timeoutsec); WebElement element = Wait.until(myCondition); ExpectedCondition<WebElement> myCondition = new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver d) { return d.findElement(By.id(“someid")); } } WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))); titleIs frameToBeAvailableAndSwitchToIt PresenseOfElement visibilityOfElement visibilityOf presenceOfAllElementsLocatedBy textToBePresentInElement textToBePresentInElementByValue titleContains invisibilityOfElementLocated elementToBeClickable elementToBeSelected stalenessOf elementSelectionStateToBe elementToBeSelected elementSelectionStateToBe
  • 4. Problem: My test environment or test case requires me to edit some cookies or create new cookies.  Solution: driver.manage.getCookieNamed(cookieName) driver.manage.addCookie(cookie) myDriver.manage().getCookieNamed(“sesssionID”); Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure); myDriver.manage().addCookie(cookie);
  • 5. Problem: I just clicked on a link and it opened a new window, now what?  Solution: Switch to the window using driver.switchTo.window(“windowHandle”) ◦ Iterate through all window handles to find the new window, wither by title or url ◦ Switch to the window using the window handle
  • 6. public String switchToWindow(String title) { try { if (prevWindow == null || prevWindow != title) { prevWindow = myDriver.getTitle(); prevWindowHandle = myDriver.getWindowHandle(); myLog.logTcStep("Saved Prev Window Title:" + prevWindow); } myLog.logTcStep("Switching To Window Title:" + title); return getHandleByTitle(title); } catch (Exception e) { } return null; }
  • 7. private String getHandleByTitle(String title) { String currentHandle = myDriver.getWindowHandle(); for (String handle : myDriver.getWindowHandles()) { if (title.equals(myDriver.switchTo().window (handle).getTitle())) { myLog.logStep("Found new window handle by title: " + handle); return handle; } } myLog.logStep("Could not find new window handle by title"); return currentHandle; }
  • 8. private String getHandleByUrl(String url) { String currentHandle = myDriver.getWindowHandle(); for (String handle : myDriver.getWindowHandles()) { if ((myDriver.switchTo().window (handle).getCurrentUrl()).contains(url)) { return handle; } } return currentHandle; }
  • 9. Problem: When I click on a link it opens a popup window, how do I close it when I am done validating it?  Solution: Use window handles and driver.switchTo().window().close() ◦ Iterate through the window handles ◦ Close everything else but the main window
  • 10. String currentWindow = myDriver.getWindowHandle(); Set<String> windows = myDriver.getWindowHandles(); for (Iterator<String> iterator = windows.iterator(); iterator.hasNext();) { String string = (String) iterator.next(); if (!currentWindow.equals(string)) { myDriver.switchTo().window(string).close(); myDriver.switchTo().window(currentWindow); Util.sleep(1000); return true; } } return false;
  • 11.  Problem: The developer for my application likes to use a lot of iframes and Selenium doesn’t seem to work.  Solution: Use driver.switchTo().frame(iFrameName) driver.switchTo().frame(iFrameIndex) ◦ Switches context to the frame ◦ Return to default context with myDriver.switchTo().defaultContent();
  • 12. List<WebElement> elements = myDriver.findElements(By.tagName("iframe")); if (elements != null) iframes = elements.size(); for (int f = 0; f < iframes ; f++) { myDriver.switchTo().frame(f); try { element = myDriver.findElement(locator); return element; }catch (Exception e) {} } return null;
  • 13. Problem: I need to hover over and menu and then click a submenu  Solution: Use the Action class hoverOverElement = waitForAndGetElement (locatorForHover); Actions action = new Actions(myDriver); action = action.moveToElement(hoverOverElement). moveToElement(waitForAndGetElement(locatorForClick)). click(); action.perform();
  • 14. keyDown click keyUp doubleClick sendKeys moveToElement clickAndHold moveByOffset release contextClick dragAndDrop
  • 15. Problem: An alert window appears and blocks the automation.  Solution: Use the Alert class (works most of the time)
  • 16. try{ Alert alert = myDriver.switchTo().alert(); // And acknowledge the alert (equivalent to clicking "OK") alert.accept(); //OK alert.dismiss(); //”X” alert.sendKeys(Keys.ENTER); //Hit Enter on keyboard myLog.logTcStep("Closing Alert"); return true; } catch (Exception e) { // no alert myLog.logTcStep("Cannot Close Alert"); e.printStackTrace(); return false; }
  • 17. Problem: AndroidDriver does not support Select, the native spinner pops up  Solution: Use Javascript injection
  • 18. WebElement select = getElement(locator); List<WebElement> options = select.findElements(By.tagName("option")); int optionNum = 0; for(WebElement option : options){ if(option.getText().equals(selection)) { try { ((JavascriptExecutor) myDriver).executeScript ("document.getElementById("newLocationSource").options["+ optionNum + "].selected = true"); Util.sleep(2000); return true; } catch (Exception e) {} break; } optionNum++; }
  • 19. Events not firing? //send enter key to select box select. sendKeys(Keys.ENTER) //dismiss the native spinner Runtime.getRuntime().exec ("cmd.exe /K "+ env.get("ANDROID_HOME") + “ /platform-tools/adb shell input keyevent 66"); //key enter
  • 20.
  • 21. Aug. 16th ◦ Open  Sept. 13th (Moved from the 20th) ◦ Lee Copeland – Topic TBD Thank You Sponsors!