![](/img/trans.png)
[英]I wish to click a button in selenium using python. I get an error 'list' object has no attribute 'click'
[英]How can we click on an icon which is list in Python Selenium ('list' object has no attribute 'click' error)?
我正在進行一個 RPA 項目,我正在嘗試通過網站進行自動化。 我正在嘗試編寫 xpad 以單擊我瞄准的對象(使用硒),但它是一個列表,我收到此錯誤; ''list' 對象沒有屬性 'click'' 我將檢查部分的圖像 (ss) 粘貼到此處和代碼下方。
site = webdriver.Chrome("D:\\Users\\user\\Desktop\\chromedriver.exe")
site.get("websiteaddress")
site.find_elements_by_partial_link_text('Findings and Action').click()
最后一行也是這個
fa = site.find_elements_by_xpath("//ul[@class='sasLeftNavNav']//li[.//span[text()='RGF_HUB_Home_MRM_appContainer_lfn_5_icn']]/li[@id='RGF_HUB_Home_MRM_appContainer_lfn_5']")
fa.click()
提前感謝您的幫助!
從瀏覽器檢查(部分):
<li id="RGF_HUB_Home_MRM_appContainer_lfn_5" role="menuitem" data-item="5" aria-label="Selected, Findings and Action" tabindex="0" class="sasLeftNavItemSelected" aria-selected="true"><span id="RGF_HUB_Home_MRM_appContainer_lfn_5_icn" data-sap-ui="RGF_HUB_Home_MRM_appContainer_lfn_5_icn" data-item="5" role="presentation" aria-hidden="true" aria-label="Findings and Action" title="Findings and Action" data-sap-ui-icon-content="" class="sapUiIcon" style="font-family:'sas-icons'"></span><span class="sasLeftNavItemState" id="RGF_HUB_Home_MRM_appContainer_lfn_5_state" data-item="5"></span><span class="sasLeftNavItemLabel" title="Findings and Action" data-item="5">Findings and Action</span></li> <span id="RGF_HUB_Home_MRM_appContainer_lfn_5_icn" data-sap-ui="RGF_HUB_Home_MRM_appContainer_lfn_5_icn" data-item="5" role="presentation" aria-hidden="true" aria-label="Findings and Action" title="Findings and Action" data-sap-ui-icon-content="" class="sapUiIcon" style="font-family:'sas-icons'"></span> <::before></::before>
find_elements_by_partial_link_text()函數返回所有找到的元素的列表。 如果您只需要一個元素,您可以使用find_element_by_partial_link_text()函數。
但是,如果您需要單擊找到與您的定位器匹配的所有元素,則可以使用:
for element in site.find_elements_by_partial_link_text('Findings and Action'):
element.click()
<html class="sap-desktop sapUiTheme-sas_corporate sapUiMedia-Std-Desktop sapUiMedia-StdExt-Desktop" dir="ltr" data-sap-ui-browser="cr99" data-sap-ui-os="win10" lang="en" data-sap-ui-animation="on"><head><base href="/SASRiskGovernanceFramework/">
<script type="text/javascript" src="resources/sap/ui/thirdparty/signals.js"></script>
<script type="text/javascript" src="resources/sap/ui/thirdparty/hasher.js"></script>
<style>
.gshHeader {
border-color: #ec66eb;
font-size: 11;
margin-bottom: 4;
}
.gshDisplay {
border-color: #6878b6;
font-size: 10;
margin-bottom: 19;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="icon" type="image/x-icon" href="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes/sas/hc/ui/commons/themes/sas_corporate/img/ico/SASLogo_toolbar.ico">
<meta content="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes/sas/hc/ui/commons/themes/sas_corporate/img/ico/SASLogo_toolbar.ico" itemprop="image">
<link rel="stylesheet" href="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes/sas/hc/ui/commons/themes/sas_corporate/splash.css" media="screen">
<meta charset="UTF-8">
<style type="text/css">.gshDisplay { border-color: #6878af; font-size: 14; margin-bottom: 11; }</style><script src="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/sap/ui/core/library-preload.js" data-sap-ui-module="sap/ui/core/library-preload.js"></script><script src="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/sas/hc/ui/core/library-preload.js" data-sap-ui-module="sas/hc/ui/core/library-preload.js"></script><link type="text/css" rel="stylesheet" href="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes/sap/ui/core/themes/sas_corporate/library.css" id="sap-ui-theme-sap.ui.core" data-sap-ui-ready="true"><link type="text/css" rel="stylesheet" href="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes/sas/hc/ui/core/themes/sas_corporate/library.css" id="sap-ui-theme-sas.hc.ui.core" data-sap-ui-ready="true"><title>ING iModel (powered by SAS® Model Risk Management)</title></head>
<body class="sapUiBody">
<style>
#sas-hc-splash-alertText {
position: absolute;
clip: rect(0px,0px,0px,0px);
}
</style>
<script id="hc-config">
(function(){
window['sap-ui-config'] = window['sap-ui-config'] || {};
var config = window['sap-ui-config'];
config.sas = config.sas || {};
config.sas.contextPath='https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework';
config.sas.appId='SASApplicationSwitcherBootstrap';
config.language='tr-tr';
config.rtl=false;
config.sas.crossDomainProxy='CASedCrossDomainProxy';
config.sas.commonsRegistryUrl='https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/rest';
config.sas.wipRegistryUrl='https://imodel.ic.ing.net:8343/SASWIPClientAccess/rest/services';
config.sas.servicePlatform='WIP';
config.sas.themeUrl='https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes';
config.sas.webdocUrl='https://imodel.ic.ing.net:8343/SASWebDoc';
config.sas.softwareComponentName='Risk Gov Frwk Mid-Tier';
config.sas.applicationSwitcherEnabled=true;
config.sas.sessionTimeoutUrl='https%3A%2F%2Fimodel.ic.ing.net%3A8343%2FSASLogon%2FTimedOut.do%3F_locale%3Dtr_TR%26_sasapp%3DRisk%2BGov%2BFrwk%2BMid-Tier%26rgfContentId%3Dmrm';
config.sas.sessionMaxInActiveInterval=1800;
config.sas.sessionTimeoutWarningDuration=300;
config.sas.userCapabilities='';
config.sas.appName = 'ING iModel (powered by SAS\u00AE Model Risk Management)';
config.theme = config.theme || 'sas_corporate';
config.themeroots = config.themeroots || {};
config.themeroots[config.theme] = config.themeroots[config.theme] || 'https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/themes';
}());
</script>
<script id="hc-precore" src="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/sas/hc/ui/core/preCore.js" data-loading="Yükleniyor" data-still-loading="Halen Yükleniyor"></script> <script>
(function(){
var config = window['sap-ui-config'];
config.modules = ['sas.hc.ui.core.library'];
config.sas.bootTask = undefined;
}());
</script>
<script src="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/resources/shcb1643626187000/sap-ui-core.js" id="sap-ui-bootstrap"></script>
<script type="text/javascript" id="hc-init">
sap.ui.getCore().attachInit(function(){
sas.log.info("appSwitcher"+sas.applicationSwitcher);
sas.applicationSwitcher.localizedStrings['discardUnsavedChanges.txt']='De\u011Fi\u015Fiklikleri atmak ve uygulamalardan \u00E7\u0131kmak m\u0131 istiyorsunuz?';
sas.applicationSwitcher.localizedStrings['unsavedChangesNotification.txt']='A\u015Fa\u011F\u0131daki uygulamalarda kaydedilmemi\u015F de\u011Fi\u015Fiklikler bulunuyor:';
$( window ).on('beforeunload',function(event){
if(sas.applicationSwitcher.isDirtyMessageEnabled()===false)
return;
var unsavedChangesMessage=sas.applicationSwitcher.getUnsavedChangesMessage();
if(unsavedChangesMessage===null){
return;
}
else{
event.returnValue=unsavedChangesMessage;
return unsavedChangesMessage;
}
});
sas.applicationSwitcher.gotoApp('RGF_HUB_Home_MRM', window.location.href, true, {'bootstrapping':true});
});
</script>
<div id="appsContainer" style="position: absolute; overflow: hidden; top: 0px; left: 0px; width: 100%; height: 100%;"><iframe id="RGF_HUB_Home_MRM_iframe" loaded="false" allowfullscreen="true" tabindex="0" src="https://imodel.ic.ing.net:8343/SASRiskGovernanceFramework/content/mrm?launchedFromAppSwitcher=true" style="width: 100%; height: 100%; border-width: 0px;"></iframe></div></body></html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.