当前位置: 首页 > 知识库问答 >
问题:

如何使用Selenium+Python向下滚动对话框

商兴朝
2023-03-14

<md-dialog aria-label="Pacientes" ng-form="mainForm" flex="70" flex-xl="40" class="ng-pristine ng-valid _md flex-xl-40 flex-70 md-transition-in" role="dialog" tabindex="-1" aria-describedby="dialogContent_573" style="">
    <md-toolbar md-theme="white" class="_md md-white-theme _md-toolbar-transitions">
        <div class="md-toolbar-tools layout-wrap layout-row" layout="row" layout-wrap="">
            <h2 flex="100" flex-gt-xs="50" class="flex-gt-xs-50 flex-100">Pacientes</h2>
            <md-input-container flex="100" flex-gt-xs="50" md-no-float="" style="padding: 0;" class="md-input-has-placeholder md-white-theme flex-gt-xs-50 flex-100">
                <input type="text" placeholder="Pesquisar" ng-model="pacienteCtrl.search" ng-change="pacienteCtrl.onChangeSearch()" class="ng-pristine ng-untouched ng-valid md-input ng-empty" id="input_572" aria-invalid="false" style=""><div class="md-errors-spacer"></div>
            </md-input-container>
        </div>
    </md-toolbar>

    <md-dialog-content class="md-dialog-content" when-scrolled="pacienteCtrl.nextPage()" id="dialogContent_573">
        <div layout="column" class="layout-column">
            <md-divider></md-divider>
            <md-list class="sd-list-pacientes" role="list">
                <!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem" style="">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-574" ng-href="https://app.simplesdental.com/simples/pacientes/11489833/sobre" href="https://app.simplesdental.com/simples/pacientes/11489833/sobre">
				
				Abraão Laurentino dos Santos
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.cpf">
                                <md-icon md-svg-icon="person" role="img" aria-label="person"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M24 24c4.42 0 8-3.59 8-8 0-4.42-3.58-8-8-8s-8 3.58-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0-16 2.67-16 8v4h32v-4c0-5.33-10.67-8-16-8z"></path></svg></md-icon>
                                <span class="grey">xxx.xxx.xxx-xx</span>
                            </span><!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-575" ng-href="https://app.simplesdental.com/simples/pacientes/11827315/sobre" href="https://app.simplesdental.com/simples/pacientes/11827315/sobre">
				
				Acyr Xavier Moreira
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.cpf">
                                <md-icon md-svg-icon="person" role="img" aria-label="person"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M24 24c4.42 0 8-3.59 8-8 0-4.42-3.58-8-8-8s-8 3.58-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0-16 2.67-16 8v4h32v-4c0-5.33-10.67-8-16-8z"></path></svg></md-icon>
                                <span class="grey">xxx.xxx.xxx-xx</span>
                            </span><!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-576" ng-href="https://app.simplesdental.com/simples/pacientes/17258954/sobre" href="https://app.simplesdental.com/simples/pacientes/17258954/sobre">
				
				Adilton Junior
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.cpf">
                                <md-icon md-svg-icon="person" role="img" aria-label="person"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M24 24c4.42 0 8-3.59 8-8 0-4.42-3.58-8-8-8s-8 3.58-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0-16 2.67-16 8v4h32v-4c0-5.33-10.67-8-16-8z"></path></svg></md-icon>
                                <span class="grey">xxx.xxx.xxx-xx</span>
                            </span><!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-577" ng-href="https://app.simplesdental.com/simples/pacientes/15922853/sobre" href="https://app.simplesdental.com/simples/pacientes/15922853/sobre">
				
				Adalberto Cortes da Silva
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.cpf">
                                <md-icon md-svg-icon="person" role="img" aria-label="person"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M24 24c4.42 0 8-3.59 8-8 0-4.42-3.58-8-8-8s-8 3.58-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0-16 2.67-16 8v4h32v-4c0-5.33-10.67-8-16-8z"></path></svg></md-icon>
                                <span class="grey">xxx.xxx.xxx-xx</span>
                            </span><!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-578" ng-href="https://app.simplesdental.com/simples/pacientes/13516998/sobre" href="https://app.simplesdental.com/simples/pacientes/13516998/sobre">
				
				Adalton Barbosa Cardoso Cunha
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.cpf">
                                <md-icon md-svg-icon="person" role="img" aria-label="person"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M24 24c4.42 0 8-3.59 8-8 0-4.42-3.58-8-8-8s-8 3.58-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0-16 2.67-16 8v4h32v-4c0-5.33-10.67-8-16-8z"></path></svg></md-icon>
                                <span class="grey">xxx.xxx.xxx-xx</span>
                            </span><!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-579" ng-href="https://app.simplesdental.com/simples/pacientes/17103848/sobre" href="https://app.simplesdental.com/simples/pacientes/17103848/sobre">
				
				Adelina de Oliveira
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!----><md-list-item class="md-2-line md-no-proxy _md" ng-repeat="paciente in pacienteCtrl.pacientes" paciente-link="" paciente="paciente" role="listitem">
                    <img ng-src="assets/img/user-default.png" class="md-avatar" src="assets/img/user-default.png">
                    <div layout="column" class="md-list-item-text layout-column">
                        <a ng-click="go()" class="sd-link" paciente="paciente" aria-label="Ir para a ficha desse paciente" md-labeled-by-tooltip="md-tooltip-580" ng-href="https://app.simplesdental.com/simples/pacientes/12563381/sobre" href="https://app.simplesdental.com/simples/pacientes/12563381/sobre">
				
				Alan Albuquerque
			</a>
                        <div layout="column" layout-gt-sm="row" class="sd-list-pacientes-info layout-gt-sm-row layout-column">
                            <!---->
                            <!----><span class="sd-list-pacientes-info-item" ng-if="paciente.celular">
                                <md-icon md-svg-icon="phone" role="img" aria-label="phone"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 48 48" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M31 2H15c-2.76 0-5 2.24-5 5v34c0 2.76 2.24 5 5 5h16c2.76 0 5-2.24 5-5V7c0-2.76-2.24-5-5-5zm-8 42c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm9-8H14V8h18v28z"></path></svg></md-icon>
                                <span class="grey">(xx) xxxxx-xxxx</span>
                            </span><!---->
                            <!---->
                            <!---->
                        </div>
                    </div>
                    <md-divider></md-divider>
                <div class="md-secondary-container"></div></md-list-item><!---->
            </md-list>
        </div>
        <div layout="column" ng-show="!pacienteCtrl.pacientes.length" layout-align="center center" class="layout-align-center-center layout-column ng-hide" aria-hidden="true" style="">
            <p class="inset">Sem resultados para a busca</p>
        </div>
    </md-dialog-content>

    <md-dialog-actions layout="row" layout-align="end center" class="layout-align-end-center layout-row">
        <button class="md-button md-ink-ripple" type="button" ng-transclude="" ng-click="pacienteCtrl.closeDialog()"> Fechar </button>
    </md-dialog-actions>
</md-dialog>

这是我想向下滚动的代码:

element=driver.find_element(by.xpath(“//div[@class='md-dialog-container']//md-list-item[30]”))#选择内容div driver.execute_script(“arguments[0].scrollintoView(true);”,element)#滚动到最后一个子节点

但我收到消息错误:

共有1个答案

夏建弼
2023-03-14
TypeError: 'str' object is not callable
Find an element given a By strategy and locator. Prefer the find_element_by_* methods when possible.
Usage :   element = element.find_element(By.ID, ‘foo’)
Return type:  WebElement
def find_element(self, by=By.ID, value=None):
    """
    Find an element given a By strategy and locator. Prefer the find_element_by_* methods when
    possible.

    :Usage:
        element = element.find_element(By.ID, 'foo')

    :rtype: WebElement
    """
    if self._w3c:
        if by == By.ID:
            by = By.CSS_SELECTOR
            value = '[id="%s"]' % value
        elif by == By.TAG_NAME:
            by = By.CSS_SELECTOR
        elif by == By.CLASS_NAME:
            by = By.CSS_SELECTOR
            value = ".%s" % value
        elif by == By.NAME:
            by = By.CSS_SELECTOR
            value = '[name="%s"]' % value

    return self._execute(Command.FIND_CHILD_ELEMENT,
                         {"using": by, "value": value})['value']
last_element = driver.find_element(By.XPATH,"//div[@class='md-dialog-container']//md-list-item[30]")
driver.execute_script("arguments[0].scrollIntoView(true);", last_element)
last_element = driver.find_element_by_xpath("//div[@class='md-dialog-container']//md-list-item[30]")
driver.execute_script("arguments[0].scrollIntoView(true);", last_element)
 类似资料:
  • 问题内容: 嗨,大家好,我是Selenium和Python的新手。我只是在抓取站点pagalguy网站。我知道如何向下滚动到页面底部,但是我需要逐步向下滚动,以便Selenium单击所有readmore按钮,但是我不知道如何逐步向下滚动,因此我像下面的一个一样硬编码 我尝试使用while循环将其自动化,但它导致错误,上面的一个可行,但是我希望它简短并循环,以便可以将其用于具有不同页面长度的所有其他

  • 问题内容: 我想向下滚动我的网页,即时通讯使用此代码滚动页面,但无法正常工作 寻求帮助 问题答案: 尝试使用下面的简单Java脚本,您可以滚动页面。

  • 请帮帮我,我想向下滚动到菜的结尾,但它停止了。我尝试的代码在这里

  • 我正在工作一个Linkedin网页刮痧项目。我正在尝试获得感兴趣的公司列表(注意,我没有使用API)。这是一个动态的网站,所以我需要滚动,而刮公司的名字。我知道如何在主窗口中这样做,但由于兴趣是一个弹出窗口,这种滚动解决方案不起作用。到目前为止我的代码是:

  • 问题内容: 我正在尝试从航班搜索页面中抓取一些数据。 此页面的工作方式如下: 您填写表格,然后单击按钮搜索-可以。当您单击按钮时,您将被重定向到包含结果的页面,这就是问题所在。例如,此页面会持续添加一分钟的结果,这没什么大不了的- 问题是要获得所有这些结果。在实际的浏览器中,您必须向下滚动页面,然后才会显示这些结果。因此,我尝试使用Selenium向下滚动。它可能在页面底部如此之快地向下滚动,或者

  • 我正试图从航班搜索页面中获取一些数据。 此页面的工作方式如下: 您填写表格,然后单击“搜索”按钮-这是确定的。当你点击按钮时,你会被重定向到有结果的页面,问题就在这里。这个页面不断添加结果,例如一分钟,这不是什么大问题-问题是要获得所有这些结果。当您在real browser中时,您必须向下滚动页面并显示这些结果。所以我尝试使用Selenium向下滚动。它在页面底部向下滚动的速度可能非常快,或者它