Search code examples
pythonpython-2.7seleniumfirefoxpyvirtualdisplay

Trouble clicking web element with python, selenium, and pyvirtualdisplay


I have a simple web crawler that logs into Twitter, goes the the following page, then grabs information from all my followers (if they are muted, etc) by clicking on the gear icon. The problem is that click functionality has stopped working on my new computer.

Also, I am using the Firefox() web driver.

Here is the code that I am using (You will need to add your own credentials for Twitter to get it working): https://gist.github.com/anonymous/4c64054d01af77ae2c5c2b39a2165d80

This code works perfectly fine on one machine, but fails to click a dom element on another. Here are some specs that might offer insight.

::GOOD BOX::
pip packages
- selenium 2.47.3
- pyvirtualdisplay 0.1.5

python 2.7
firefox 41.0
lib32z-dev 1:1.2.8.dfsg-1ubuntu1
python-lxml 3.3.3-1ubuntu0.1
python-dev 2.7.5-5ubuntu3
build-essential 11.6ubuntu6

-------------------------

::BAD BOX::
pip packages
- selenium 2.53.6
- pyvirtualdisplay 0.2

python 2.7
firefox-mozilla-build 47.0.1-0ubuntu1 (not sure why I need this, the other box doesn't seem to have it.  But things break if I remove it)
firefox 47.0.1
python-dev 2.7.11-1
libxml2-dev 2.9.3+dfsg1-1ubuntu0.1
libxslt-dev (1.1.28-2.1)
build-essential 12.1ubuntu2

When I run this code on the "bad box" and do not catch the exceptions, I get the following:

selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (464, 1). Other element would receive the click: <div class="container"></div>

Solution

  • It could be due to a window too small where the targeted element ends up hidden under another one. Try to set the original size:

    driver.set_window_size(1920, 1200)
    

    You could also try to change the scroll behaviour if your element ends up hidden under the top banner:

    DesiredCapabilities.FIREFOX["elementScrollBehavior"] = 1 #scroll bottom instead of top
    driver = webdriver.Firefox()