How to set focus on a section of my web page then scroll down

核能气质少年 提交于 2020-01-11 08:19:06

问题


using protractor I would like to first set focus on a left pannel in my web page then scroll down in order to click on a filter. Any idea how to do this using protractor syntax? Here is my HTML :

<section id="filters" style="height: 266px; overflow: hidden;" tabindex=
"5076">
    <div class="ng-binding" id="currentSearchTitle">
        Current search
    </div>

    <div id="currentSearch">
        <div id="searchBlock">
            <div id="jobTypeBlock">
                <div class="ng-binding" id="jobTypeTitle">
                    Filter by job type
                </div>

                <div class="ng-scope">
                    <div class="ng-scope">
                        <div class="ng-scope">
                            <div class="ng-scope">
                                <div class="ng-scope">
                                    <div class="ng-scope">
                                        <div class="ng-scope"></div>

回答1:


To set the focus on your panel you can maybe click on it:

element(by.id('filters')).click();

Then to scroll to your filter, you can execute a client side script:

var filter = browser.findElement(by.id('jobTypeTitle'));
var scrollIntoView = function () {
  arguments[0].scrollIntoView();
};
browser.executeScript(scrollIntoView, filter);

You can have a look at the webdriverjs doc.




回答2:


You can use this too: browser.executeScript("arguments[0].scrollIntoView();", basePage.faqText.getWebElement());

I does the magic in one line.

basePage.faqText is the element that I want to scroll here.



来源:https://stackoverflow.com/questions/21933268/how-to-set-focus-on-a-section-of-my-web-page-then-scroll-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!