Skip to content

Commit 78c42f2

Browse files
committed
Implemented action chains and wait conditions
1 parent aa93577 commit 78c42f2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

scrapy_webdriver/action_chains.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from functools import partial
2+
3+
from selenium.webdriver.common.action_chains import ActionChains
4+
from selenium.webdriver.support import expected_conditions as ec
5+
from selenium.webdriver.support.wait import WebDriverWait
6+
7+
8+
class WaitingActionChains(ActionChains):
9+
"""ActionChains that wait on conditions."""
10+
def wait(self, timeout, condition=None, name=None, args=None):
11+
"""Add a waiting action to the stack."""
12+
if args is None:
13+
args = []
14+
if name:
15+
condition = getattr(ec, name)(*args)
16+
if condition is None:
17+
raise ValueError('You must provide a condition, either directly '
18+
'or by specifying its name.')
19+
20+
def do_wait(condition):
21+
return WebDriverWait(self._driver, timeout).until(condition)
22+
self._actions.append(partial(do_wait, condition))
23+
return self

scrapy_webdriver/download.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ def _do_inpage_request(self, request, spider):
4040
"""Perform an action on a previously webdriver-loaded page."""
4141
log.msg('Running webdriver actions %s' % request.url, level=log.DEBUG)
4242
request.actions.perform()
43-
import time; time.sleep(2)
4443
return WebdriverResponse(request.url, request.manager.webdriver)

0 commit comments

Comments
 (0)