Čamo
Čamo

Reputation: 4160

Selenium moveToElement() to Selenide

I am starting with Selenide and would like to know if is possible to scroll to the element. In Seleniu the code looks like:

    Actions actions = new Actions(getWebDriver());
    actions.moveToElement(loadMore).build().perform();

I need to scroll to lement cause it is not clickable if it is outside the screen.

Upvotes: 1

Views: 8403

Answers (3)

Sers
Sers

Reputation: 12255

Selenide has scrollIntoView method, that implements JavaScript's scrollIntoView and scroll element to the specific position:

// the top of the element will be aligned to the top.
$("").scrollIntoView(true).click();

// element will be aligned to the center. 
$("").scrollIntoView("{behavior: \"instant\", block: \"center\", inline: \"center\"}").click();

Upvotes: 4

methamorf
methamorf

Reputation: 3

You should be able to click on an element even if it's outside the screen ( Make sure the XPath is correct!) You can use actions.scrollIntoView(actions.findElement(By.xpath(xpath))

Upvotes: 0

0buz
0buz

Reputation: 3503

Would this not suffice?

actions.moveToElement(loadMore).click().build().perform()

Upvotes: 1

Related Questions