【发布时间】:2016-12-05 18:52:16
【问题描述】:
我有一个简单的网络爬虫,它可以登录 Twitter,进入下一页,然后通过单击齿轮图标从我的所有关注者(如果他们被静音等)那里获取信息。问题是点击功能在我的新计算机上停止工作。
另外,我正在使用 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 直到元素可点击...:)
-
我应该等到找到元素,还是等到点击它?
-
您应该在使用 WebDriverWait 查找元素期间等待...:)
标签: python python-2.7 selenium firefox pyvirtualdisplay