【发布时间】:2020-08-31 01:54:09
【问题描述】:
我有一个来自医疗网络应用程序的对话框,它在第一个屏幕上仅显示 30 位患者,要查看更多患者,我向下滚动对话框,当我接近第 30 位患者时,它会显示更多 30 位患者。
当我在新窗口中打开他们的链接配置文件并收集信息并保存在 xmls 文件中时,我试图在该对话框中显示 2000 多个参与者。
如何使用 Python + Selenium 向下滚动?
这是对话框屏幕:
此 html 是包含 6 个第一次患者和 第三十,发不完30个(字数限制):
<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) #滚动到最后一个子节点
但我收到消息错误:
element = driver.find_element(By.XPATH("//div[@class='md-dialog-container']//md-list-item[30]")) #选择内容div的最后一个孩子 TypeError:“str”对象不可调用
【问题讨论】: