Reputation: 77
I have a dialog box from a medical web app which shows only 30 patients in the first screen, to view more pacients i have scroll down the dialog box and when i close to the thirtieth pacient it shows 30 more.
I'm trying to show more than 2000 paciente on that dialog box while I'm opening in a new window their link profile and collecting info and saving in a xmls file.
How can I scroll down using Python + Selenium?
This is the dialog box screen:
This html is the dialog box with the 6 first firsts patients and thirtieth, I couldn't post all the 30 (character limit):
<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>
This is my code where i'm tryong to scroll down:
element = driver.find_element(By.XPATH("//div[@class='md-dialog-container']//md-list-item[30]"))#Select last child of content div driver.execute_script("arguments[0].scrollIntoView(true);", element) #Scroll to last child node
But I'm receving the message error:
element = driver.find_element(By.XPATH("//div[@class='md-dialog-container']//md-list-item[30]")) #Select last child of content div TypeError: 'str' object is not callable
Upvotes: 2
Views: 2306
Reputation: 7708
This error message...
TypeError: 'str' object is not callable
...implies that your program have invoked a function()
which is actually a property
.
As per Selenium doc this is the right method signature:
find_element(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’) Return type: WebElement
And this is mentioned in doc
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']
So as per method signature you should use either
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)
OR
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)
Upvotes: 2