0

I am using Protractor for automation. There is a page in an application where there is one web element button which Protractor can not find while execution. That web element is present in DOM but it is not visible on screen. Protractor is able to find & click the element only when we scroll down in application. But this is not a good approach as every time I have to place the code of page_Down.

Any help here ?

3
  • 1
    That's desired behaviour. Protractor behaves like a user. A user can't press a button, that is out of sight . There is an option to scroll down until an element is visible. Try with that. Commented Nov 26, 2017 at 13:58
  • @ErnstZwingli: Thanks for letting me know. You suggested that there is option to scroll down until an element is visible. Could you please let me know about this option. Commented Nov 27, 2017 at 5:59
  • Sudharsan Selvaraj described it in his answer. Commented Nov 27, 2017 at 10:05

1 Answer 1

3

You can simply use ele.scrollIntoView(true) method to make an element visible in view port.

var button = element(by.buttonText("Login")); browser.executeScript("arguments[0].scrollIntoView(true)",button.getWebELement()): browser.wait(EC.elementToBeClickable(button),5000); button.click(); 

Here you find the JavaScript definition of scrollIntoView()

Sign up to request clarification or add additional context in comments.

1 Comment

I faced synchronization issues, this worked for me: browser.wait(EC.elementToBeClickable(button),5000).then(()=>{ browser.executeScript("arguments[0].scrollIntoView(true)",button.getWebElement()); ; });

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.