Forum Discussion

funmay's avatar
funmay
Contributor
7 years ago
Solved

How can i Scroll to view an element and click in TestComplete with Javascript?

How can i Scroll to view an element and click in TestComplete with Javascript for web testing? Does TestComplete supports this control(Scroll into view element ).

 

See the example of selenium code controls  below:

 

var element = driver.FindElement(By.id("element-id"));

Actions actions = new Actions(driver);

actions.MoveToElement(element);

actions.Perform();

 

-------------------------------------------------------------------------------------------------

See the example of selenium code with Javascript:

(JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

  • Hi,

     

    Yes, scrollIntoView(true/false) is a native method that is supported by all browsers and can be used to scroll the element into view. Something like that:

    var element = page.FindChild(...);

    if (element.Exists)

    {

      element.scrollIntoView(true);

      element.click();

    }

     

    Update: ah, just noted that I duplicated reply from cunderw...

2 Replies

  • cunderw's avatar
    cunderw
    Community Hero

    FindChildEx would be similar to the driver.FindElement function, and element.scrollIntoView will allow you to scroll to the object. 

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Yes, scrollIntoView(true/false) is a native method that is supported by all browsers and can be used to scroll the element into view. Something like that:

    var element = page.FindChild(...);

    if (element.Exists)

    {

      element.scrollIntoView(true);

      element.click();

    }

     

    Update: ah, just noted that I duplicated reply from cunderw...