A
A
Alexander Vasilenko2020-01-06 18:27:16
Java
Alexander Vasilenko, 2020-01-06 18:27:16

Why did Selenium WebDriver redirect to Google search page?

Remembered Selenium, decided to practice drag-and-drop on this page: https://www.seleniumeasy.com/test/drag-and-drop-de...
Actually, here is the code that I'm trying to implement my plan:

public class DragAndDropDemoPage extends Page {

    public DragAndDropDemoPage(WebDriver driver) {
        super(driver);
        navigateTo();
    }

    @Override
    public void navigateTo() {
        driver.get(Urls.DRAG_AND_DROP_PAGE_URL);
    }

    public void dragAndDropElementWithIndex(int index) {
        List<WebElement> elements = findElementsByCss("span[draggable=true]");
        new Actions(driver).dragAndDrop(elements.get(index), findElementByCss("div#mydropzone")).build().perform();
    }
}

For some reason, it throws me to the Google search page. And we are looking for, as a result, by the name of the element that we tried to drop. What really happened here. I read a little on the Internet that all this can be related to HTML5 and the attribute of the draggable tag. In general, it is not yet clear why it happened that we dropped the element into the search bar.
Are there any ideas?
PS: Below is the Page superclass:
public abstract class Page {
    WebDriver driver;

    public Page(WebDriver driver) {
        this.driver = driver;
    }

    public abstract void navigateTo();

    protected WebElement findElementByCss(String cssSelector) {
        return driver.findElement(By.cssSelector(cssSelector));
    }

    protected List<WebElement> findElementsByCss(String cssSelector) {
        return driver.findElements(By.cssSelector(cssSelector));
    }

    protected WebElement findByXpath(String xpath) {
        return driver.findElement(By.xpath(xpath));
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
1001001, 2020-01-06
@1001001

So everything seems to be logical) Selenium does not work well with html5 drag-and-drop, but the motion event is still generated (most likely))).
And it goes to Google, because. your cursor is physically located on the search bar of the browser (I will assume that the IDE start button is in that place). So you took an element, js calculated the coordinates, they ended up in the search bar, and threw it there, a search took place

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question