0

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()
Aymen
  • 3
  • 1

3 Answers3

0

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.

Update :

driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://ds.maps.arcgis.com/apps/dashboards/c8f1c81fa9d041da8de7fe5ea9193c7f")
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'Assumption')]"))).click()

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

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.

Kazi
  • 381
  • 2
  • 13
0
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:

enter image description here

Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32