I am tried to locate an element on web application but its not working. below the code source for the web page and python script.
<div class="widget-body flex-fluid full-width flex-vertical overflow-y-auto overflow-x-hidden">
<div class="feature-list">
<div class="flex-horizontal feature-list-item">
<!---->
<div class="flex-fluid list-item-content overflow-hidden">
<div class="external-html">
<p><span style="font-size:12px">Ascension</span></p>
</div>
</div>
<!----></div>
<div class="flex-horizontal feature-list-item active">
<!---->
<div class="flex-fluid list-item-content overflow-hidden">
<div class="external-html">
<p><span style="font-size:12px">Assumption</span></p>
</div>
</div>
<!----></div>
<div class="flex-horizontal feature-list-item">
<!---->
<div class="flex-fluid list-item-content overflow-hidden">
<div class="external-html">
<p><span style="font-size:12px">East Baton Rouge</span></p>
</div>
</div>
The python code I used give me an error AttributeError: 'list' object has no attribute 'click':
from selenium import webdriver
Driver='C:/Python27/chromedriver.exe'
url='https://ds.maps.arcgis.com/apps/dashboards/c8f1c81fa9d041da8de7fe5ea9193c7f'
driver = webdriver.Chrome(Driver)
driver.get(url)
elem=driver.find_elements_by_xpath('.//span[contains(text(), "Assumption")]')
elem.click()
CodePudding user response:
This xpath
.//span[contains(text(), "Assumption")]
is wrong, try this instead :
//*[contains(text(), "Assumption")]
Also, it's recommended to use explicit-wait to click on a web element.
CodePudding user response:
You are using find_elements_by_xpath
which returns a list so the mentioned error is occurring. You should use find_element_by_xpath
and the click should work fine.