Search code examples
pythonseleniumweb-scrapingdata-sciencedata-analysis

Web Scraping error in while using Search.submit()


I am trying to do web scraping to weather data from: https://www.wunderground.com/history/daily/us/dc/washington/KDCA

Here is HTML:

<div _ngcontent-app-root-c136="" id="wuForm" class="ui-front wu-form">
   <div _ngcontent-app-root-c136="" id="wuSearch-contain" class="wu-search-contain ng-star-inserted"><label _ngcontent-app-root-c136="" for="wuSearch" class="visuallyHidden">Search</label><input _ngcontent-app-root-c136="" type="search" name="query" value="" id="wuSearch" placeholder="Search Locations" aria-label="Search" autocomplete="off" class="wu-search ng-untouched ng-pristine ng-valid"><span _ngcontent-app-root-c136="" class="close-search"><i _ngcontent-app-root-c136="" class="material-icons">close</i></span><span _ngcontent-app-root-c136="" class="geolocate-wrap"><i _ngcontent-app-root-c136="" class="material-icons">gps_fixed</i></span></div>
   <!----><!---->
   <search-autocomplete _ngcontent-app-root-c136="" _nghost-app-root-c135="">
      <ul _ngcontent-app-root-c135="" tabindex="0" class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all hide">
         <li _ngcontent-app-root-c135="" class="ui-autocomplete-geolocate ng-star-inserted">
            <div _ngcontent-app-root-c135="" class="mimic-a menu-geolocate"><i _ngcontent-app-root-c135="" class="material-icons">gps_fixed</i>Find Nearest Station </div>
         </li>
         <!----><!----><!----><!----><!----><!---->
         <li _ngcontent-app-root-c135="" class="ui-autocomplete-last ui-menu-item manage-favorites"><a _ngcontent-app-root-c135="" tabindex="-1" href="/member/favorites" class="ui-corner-all">Manage Favorite Cities</a></li>
      </ul>
   </search-autocomplete>
</div>

I started with

driver = webdriver.Chrome(r'C:\Users\bno00\Downloads\chromedriver_win32\chromedriver.exe')
driver.get('https://www.wunderground.com/history/daily/us/dc/washington/KDCA')

and it's working fine then when I trying to send zipcode to search field by using .submit():

zipcode='22202'
xpath='//*[@id="wuSearch"]'
search=driver.find_element_by_xpath(xpath)
search.clear() 
search.send_keys(zipcode)
search.submit() #error occurs here

The error is:

NoSuchElementException: Message: no such element: Unable to locate element:{"method":"xpath","selector":"./ancestor-or-self::form"} (Session info: chrome=89.0.4389.114)


Solution

  • That <input> tag is not part of a form. You can't submit it. You either need to send a newline, or click the gps_fixed icon that triggers the search.