- Working on Desktop Browsers(mostly known) using Selenium WebDriver
- Working on Mobile Browsers(ChromeDriver, SafariDriver) using Appium
tried
Selenium WebDriver : getSize() Vs getLocation()
getSize() : will return the “Dimension” object, from which we can get Height and Width of specific element
Dimension vDimesions = vDriver.findElement(By.id(“id
System.out.println(“Height :” + vDimesions.height + ”Width : “+ vDimesions.width);
getLocation() : will return the “Point” object, from which we can get X and Y coordinates of specific element
Point vPoint=driver.findElement(By.id(“id
Selenium WebDriver – Using AdvancedUserInteractions API
Actions vMyActions = new Actions(vDriver);
vMyActions keyDown(Keys.CONTROL)
.click(someElement)
.click(someOtherElement)
.keyUp(Keys.CONTROL);
Then get the action:
Action vBindAction = vMyActions.build();
And execute it:
vBindAction.perform();
- It supports single and composite actions for Mouse and Keyboards
- It supports most of common browsers including mobile browsers
Following are my reusable custom actions, will add more as needed 🙂
1. MouseMove
Move mouse over an element, usually to get hover
Locatable vElement = (Locatable) vDriver.findElement(by);
Mouse vMouse = ((HasInputDevices) vDriver).getMouse();
vMouse.mouseMove(vElement.getCoordinates());
2. Drag and drop
I need to drag and element on some other element,
vFirtElement = vDriver.findElement(By.id(“id));
vContaingerElement = vDriver.findElement(By.id(“containerid));
new Actions(vDriver). dragAndDrop(vFirtElement, vContaingerElement).build().perform();
3. Drag and Drop By
I need to drag and element from one place to other,
vElementToDrag = vDriver.findElement(By.id(“id”));
new Actions(vDriver).dragAndDropBy(vElementToDrag, 120, 1100).build().perform();
4. Select multiple elements
If I need to check/select multiple list items,
List
Actions vClickMultiple = new Actions(vDriver);
vClickMultiple.clickAndHold(vList.get(1))
.clickAndHold(vList.get(2))
.click();
Action vBindActions = vClickMultiple.build();
vBindActions.perform();
5. Slide
we can use dragAndDropBy to emulate sliding event
vElementToSlide = vDriver.findElement(By .className(“class”));
new Actions(vDriver).dragAndDropBy(vElementToSlide, 120, 0).build().perform();