我有一个简单的网络爬虫,登录到Twitter,转到下一页,然后通过点击所有我的追随者(如果他们被静音等)齿轮图标。问题是点击功能已停止在我的新电脑上工作。使用python,selenium和pyvirtualdisplay点击web元素的问题
此外,我使用Firefox()网络驱动程序。
这里是我使用(需要添加自己的凭据Twitter并得到它的工作)的代码:https://gist.github.com/anonymous/4c64054d01af77ae2c5c2b39a2165d80
此代码工作完全正常一台机器上,但不能点击DOM元素另外一个。以下是一些可能提供见解的规格。
::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
当我运行的“坏盒子”这个代码,并没有捕捉到的异常,我得到如下:
selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (464, 1). Other element would receive the click: <div class="container"></div>
异常明确指出,其他元素将获得点击的手段你的实际元素是由其他元素的div覆盖..当你要找到元素的一些进度条仍然在覆盖元素的页面上时可能是可能的。所以你需要等待使用WebDriverWait,直到元素可点击... :) –
我应该在找到元素之前等待,还是在点击之前等待? – Tyrick
您应该在使用WebDriverWait ...找到元素期间等待:) :) –