0

I am trying to use selenium in python to input a search into a website.

From the examples I have seen, the tag, class, id etc is targeted and a value is inserted using

inputElement.send_keys('example')

On a webpage I'm trying to target a search bar that takes a zip code, input a zip so that I can scrape the resulting page but I'm having trouble.

<form class="geoLoc" action="javascript:void(0);" data-id="d866e6d3-106a-468a-8428-9fce1c8c51b6" data-baseurl="">
<fieldset class="search">
    <div class="search-input-wrap">
        <input type="tel" name="geolocation" maxlength="5" data-mask="00000" placeholder="Update Your ZIP Code" autocomplete="off">
        <div class="cta geoloc-btn">
            <button type="submit"><span>GO&nbsp;&nbsp;></span></button>
        </div>
    </div>
</fieldset>

I use the following code to target the form:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://example.com")

login_form = driver.find_element_by_class_name('search-input-wrap')

login_form.send_keys("55555")

Whether I use the solution above or Paulo's answer I get the following error

Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/fsauceda/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 322, in send_keys
        self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
      File "/Users/fsauceda/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 448, in _execute
        return self._parent.execute(command, params)
      File "/Users/fsauceda/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 196, in execute
        self.error_handler.check_response(response)
      File "/Users/fsauceda/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
    Stacktrace:
        at fxdriver.preconditions.visible (file:///var/folders/tc/12qc3v0j47x0t6djfmzpb9200000gn/T/tmpem5v0u/extensions/[email protected]/components/command-processor.js:9982)
        at DelayedCommand.prototype.checkPreconditions_ (file:///var/folders/tc/12qc3v0j47x0t6djfmzpb9200000gn/T/tmpem5v0u/extensions/[email protected]/components/command-processor.js:12626)
        at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/tc/12qc3v0j47x0t6djfmzpb9200000gn/T/tmpem5v0u/extensions/[email protected]/components/command-processor.js:12643)
        at DelayedCommand.prototype.executeInternal_ (file:///var/folders/tc/12qc3v0j47x0t6djfmzpb9200000gn/T/tmpem5v0u/extensions/[email protected]/components/command-processor.js:12648)
        at DelayedCommand.prototype.execute/< (file:///var/folders/tc/12qc3v0j47x0t6djfmzpb9200000gn/T/tmpem5v0u/extensions/[email protected]/components/command-processor.js:12590)
4
  • That error message is not very helpful. Is there something like "NoSuchElementException" a few lines above? Also, see if this answer helps. Particularly the part about implicitly_wait. Commented Sep 2, 2015 at 22:27
  • @PauloAlmeida the element is hidden. Do you know I make it visible? Maybe this stackoverflow.com/questions/27244589/… Commented Sep 2, 2015 at 22:31
  • Try this answer Commented Sep 2, 2015 at 22:37
  • Is there more than one element of the type you are searching for? What if you do driver.find_elements_by_name('geolocation').length? Does it return more than 1? (I don't know python so maybe it's not .length?) Commented Sep 3, 2015 at 0:57

1 Answer 1

0

You are finding the div, not the input. You can do this:

field = driver.find_element_by_name('geolocation')

See alternatives in the documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer Paulo. I tried that as well and should of included it, but that does not work either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.