最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set focus on a section of my web page and then scroll down - Stack Overflow

programmeradmin4浏览0评论

Using Protractor, I would like to first set focus on a left panel on my web page, and then scroll down in order to click on a filter.

How can I do this using the 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>

Using Protractor, I would like to first set focus on a left panel on my web page, and then scroll down in order to click on a filter.

How can I do this using the 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>
Share Improve this question edited Nov 16, 2022 at 20:48 Peter Mortensen 31.6k22 gold badges109 silver badges133 bronze badges asked Feb 21, 2014 at 11:31 ZiwdigforbugsZiwdigforbugs 1,2149 gold badges25 silver badges44 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 21

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

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.

发布评论

评论列表(0)

  1. 暂无评论