Selenium With Java and Python For Mobile Apps & Web Apps......!

Monday, 18 May 2015

Keyboard interactions and Mouse interactions in Selenium Web Deiver.

The Advanced User Interactions API is a new, more comprehensive API for describing actions a user can perform on a web page. This includes actions such as drag and drop or clicking multiple elements while holding down the Control key.
For Example...

    /**
     * for press Enter
     */
    public void  enter()
    {
        Actions act=new Actions(Driver.driver);
        act.sendKeys(Keys.ENTER).perform();
    }

    /**
     * for save
     */
    public void  save()
    {
        Actions act=new Actions(Driver.driver);
       
        act.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0073')).perform();
    }

    /**
     * for Paste
     */
    public void  paste()
    {
       
       
        Actions act=new Actions(Driver.driver);
        act.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0076')).perform();
    }

    /**
     *  for Cut
     */
    public void  cut()
    {
       
        Actions act=new Actions(Driver.driver);
        act.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0078')).perform();
    }

    /**
     * For Right click
     * @param wb
     */
    public void  rightClickOnwebElement(WebElement wb)
    {
       
        Actions act=new Actions(Driver.driver);
        act.contextClick(wb).perform();
    }

        /**
         * For Drag And Drop
         * @param srcwb
         * @param dstwb
         */
        public void  dragAndDrop(WebElement srcwb,WebElement dstwb)
        {
           
            Actions act=new Actions(Driver.driver);
            act.dragAndDrop(srcwb, dstwb).perform();
        }

        /**
         * Double click
         */
        public void  doubleClick()
        {
           
            Actions act=new Actions(Driver.driver);
            act.doubleClick().perform();
        }
   

0 comments:

Post a Comment

Translate

Popular Posts

Total Pageviews