Presentation is loading. Please wait.

Presentation is loading. Please wait.

Selenium HP Web Test Tool Training

Similar presentations


Presentation on theme: "Selenium HP Web Test Tool Training"— Presentation transcript:

1 Selenium HP Web Test Tool Training
Portnov Computer School Selenium HP Web Test Tool Training Test Automation For Web-Based Applications Presenter: Ellie Skobel

2 Actions and JavaScript
Day 10 Actions and JavaScript

3 Problem WebDriver object contains only basic keyboard and mouse action: click sendKeys clear Modern web UI often requires more advanced methods of interaction: drag and drop mouse over right click click and hold

4 Solution: Actions (Action Chains)
Actions are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions. This is useful for doing more complex actions like hover over and drag and drop.

5 How It Works Declare a variable to hold an instance of the Actions class Actions my_action; Create a new instance on the Actions class by passing WebDriver object to the Actions() constructor WebDriver driver = new FirefoxDriver(); my_action = new Actions(driver);

6 How to Use Actions Add on actions one at a time
my_action.moveToElement(element); my_action.click(another_element); my_action.perform(); Or add all actions at once my_action .moveToElement(element) .click(another_element) .perform();

7 Problem WebDriver object does not provide a way to scroll the page
Modern websites often contains UI elements that change style / visibility / size / etc. in response to the currently viewable area of the page: Floating ads Back to the top links

8 Solution: JavaScript Most WebDriver drivers implement the JavascriptExecutor interface This gives them the ability to inject and execute javascript within the current page of the current window JavaScript can be used to scroll to the top/bottom of the page, or any element

9 How It Works Declare a variable to hold an instance of the JavascriptExecutor JavascriptExecutor jse; Cast at existing instance of WebDriver object into JavascriptExecutor type WebDriver driver = new FirefoxDriver(); jse = (JavascriptExecutor)driver;

10 How to Use JavascriptExecutor
Use the built in executeScript() command to execute any javascript code withing the current page of the current browser window js_code = “document .getElementById('someId').width = 350;” jse.executeScript(js_code);

11 Useful JS Tricks Scroll to the bottom of the page
Scroll to the bottom of a specific element Change element width/style/position/… Assign temporary ID Enable / disable elements

12 Scroll WebElement element = driver.findElement( By.xpath("//tr/td[8]/div[2]/input")); js_code = "window.scrollTo(0, document.body.scrollHeight);” OR js_code = "document.getElementById('answers').scrollInt oView();" js.executeScript( js_code, element);

13 Assign a temporary ID WebElement element = driver.findElement( By.xpath("//tr/td[8]/div[2]/input")); js_code = "arguments[0].setAttribute( 'id', 'new_unique_id')" js.executeScript( js_code, element);


Download ppt "Selenium HP Web Test Tool Training"

Similar presentations


Ads by Google