0

I have a webpage to be tested which has a button at the footer of the page. When i click it, there should be an error message shown near to it.

I was successful in automating this scenario but the issues that , page view does not scroll automatically to page footer. So, on test failures the screenshot i get does not have footer region of the page and thus cannot tell why the test failed.

I have tackled this issue by scrollingto the button element using javascript:

await browser.executeScript('arguments[0].scrollIntoView()', element);

But moving to each element in my test suite through a custom script does not look advisable.

Is there a better way to automatically scroll to the element with which the webdriver api is interacting?

For instance , if i click the button then the browser scrolls automatically to page footer and if i again click the title of page, then the browser scrolls back to top?

0

This is what the Actions class is for, there is a "moveToElement()" function in each implementation. This is more or less how it will look like in Protractor:

browser.actions().mouseMove(element).click().perform();   

This link explains the usage

  • SO you are suggesting replace all clicks with actions()? – PDHide Nov 5 at 16:38
  • I once had a base class which did it, it handled a bunch of other stuff as well – Moro Nov 5 at 20:14
0

If I understand the question correctly, you only need to manually move to the element on test failure. In normal circumstances, the driver is automatically moving to any element it needs to interact with?

I would suggest using error handling to execute the "scrollIntoView" code that is in your question.

The Protractor FAQs show how you implement error handling:

How can I catch errors such as ElementNotFound?

WebDriver throws errors when commands cannot be completed - e.g. not being able to click on an element which is obscured by another element. If you need to retry these actions, try using webdriverjs-retry. If you would just like to catch the error, do so like this

elm.click().then(function() { /* passing case */}, function(err) { /* error handling here */})
  • driver does not move automatically to elements. For example, if i have a text box at the end of the page and i do textbox.sendKeys("Text"). the text field gets the data but the browser will not be scroll down to the text box, I will be able to see only the top session of the page and have to add browser sleep and manually scroll down to see whether the data was entered to textbox – PDHide Nov 8 at 13:38
  • 1
    Oh wow that's kinda gross on Protractor's side. I'll see if I can come up with a nice, clean way to do this over the weekend. – anonygoose Nov 8 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.