cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Contributor

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);

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

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...

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

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

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


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Community Hero

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

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...

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors