1

I'm realizing a script using Selenium Webdriver with Python to crawl some webpages, but I have a particular problem. At a certain point, I should take an input element and send a key, and on my local PC the script works well, while on my server this element results invisible. The HTML part of the page is:

<div class="class1" style="width: 309px;">
   <div class="sPb-a">
      <div class="class2" style="display: none;" aria-hidden="true">
         www.lol.com
      </div>
   <input class="class3" type="text" dir="ltr" style="width: 301px;"></input>
   </div>
   <div></div>
</div>

In Python, this is my code:

elem = browser.find_element_by_xpath("//input[@style='width: 301px;']")
elem.clear()
time.sleep(1)
elem.send_keys('lol')
time.sleep(1)

But when I call the method clear on the element, the script catch the following error:

Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:9982)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12626)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12643)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12648)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpma637_/extensions/fxdriver@googlecode.com/components/command-processor.js:12590)

I would like also to say some two additional information:

  • There is only one element with width: 301px and this error happens also if I try to capture the element in another ways, so this element is unique
  • The configuration between my local PC (where the script works well) and my server (where there is the problem) is the same (python version, selenium version, browser version, operating system version)

Do you know any solution? Thanks a lot

hasmet
  • 758
  • 3
  • 13
  • 32
  • Please, add more info. What browser and webdriver versions are you using? And what are the steps before the code you've provided. This could narrow the problem – Furious Duck Aug 27 '15 at 20:09

1 Answers1

0

I can think of a couple things that may be worth checking. You may need to wait a little longer for the page to load. I had some issues with server latency on my tests causing some things to fail, so it is worth checking.

The other thing people tend to run into is addressed here. Sometimes when an element is not visible in your browser window, your WebDriver won't be able to find it. There are some code snippets here for scrolling your browser window (they're in Java in the link, but the switch to Python should be fairly straightforward). Just drop that code before you use find_element_by_xpath() and that may take care of it. Good luck!

Community
  • 1
  • 1
Tyler
  • 197
  • 3
  • 13
  • Uhm unfortunately I have verified already the first point inserting some waiting times but the situation doesn't change Additionally, the element is visible from the browser window.....I have tried a couple of solution from other answer but they don't work – hasmet Aug 27 '15 at 14:44
  • 1
    Out of curiosity, is there a particular reason why you are using the Xpath rather than `find_element_by_class_name()` and have you tried using by class name for this element? – Tyler Aug 27 '15 at 17:53
  • In my case I am able to solve some issues by directly using `find_element_by_class_name()` and others in http://selenium-python.readthedocs.io/locating-elements.html, but there are always exceptions... – Carl H Oct 15 '16 at 21:59