Issue
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()
Solution
wait=WebDriverWait(driver, 10)
url='https://ds.maps.arcgis.com/apps/dashboards/c8f1c81fa9d041da8de7fe5ea9193c7f'
driver.get(url)
elem=wait.until(EC.element_to_be_clickable((By.XPATH,"//span[.='Assumption']")))
elem.click()
All you need to do is wait for the element and then click on it. Previously you had no waits so the page loading caused issues not finding it. Also you were trying to find multiple elements and not just one so you had an array so you could have used elem[x].click() and etc.
Imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Outputs:
Answered By - Arundeep Chohan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.