vendredi 26 avril 2019

Drag & Drop Not Working in Selenium WebDriver For google.com

Can not drag the image of GOOGLE logo to Search field from www.google.com. Tried with Acion Class, even JavascriptExecutor.

        driver.get("https://www.google.com");

//      Element which needs to drag [Google Logo].          
        WebElement from=driver.findElement(By.id("hplogo"));    

//      Element on which need to drop [Google Search-bar].      
        WebElement to=driver.findElement(By.name("q"));

//      Using Action class for drag and drop.       
        Actions act=new Actions(driver);                    

//      Dragged and dropped.        
        act.dragAndDrop(from, to).build().perform();    

/*      JavascriptExecutor _js = (JavascriptExecutor)driver;
        _js.executeScript("$(arguments[0]).simulate('drag-n-drop', 
        {dragTarget:arguments[1],interpolation: 
        {stepWidth:100,stepDelay:50}});", from, to);             
*/

I want to drag & hold the Google Image, then want Drop image to the search box, but nothing happened. Manually if I drag and drop, I found image link like https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png in input serach box.

Even the below code works perfectly but not works for google.com!

public class DragAndDrop {
    public static void main(String args[]) throws InterruptedException
    {
        System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://jqueryui.com/resources/demos/droppable/default.html");
        Thread.sleep(10000);
        Actions act=new Actions(driver);
        WebElement drag = driver.findElement(By.xpath(".//*[@id='draggable']"));
        WebElement drop = driver.findElement(By.xpath(".//*[@id='droppable']"));
        act.dragAndDrop(drag, drop).build().perform();
    }

Aucun commentaire:

Enregistrer un commentaire