Selenium-rc: Is there a way to send a buffer of requests
Lets say I have a list of links and want to click a link at random:
<div id="divA">
<a> first link </a>
<a> second link </a>
...
</div>
It isn't the smartest of ways (and if you have a better solution please tell me) but what I currently do is (roughly):
l = []
for i in range(numOfLinks):
xpath = '//div[@id="divA"]/a[%d]'%i
txt = sel.getText(xpath)
l.append(xpath, txt)
xpath,linkName = random.choice(l)
sel.click(xpath)
The main problem of this solution is that it sends many requests to selenium. My question is: is 开发者_运维百科there a way of saving all these requests in a buffer and sending them at once?
are you using the text for anything?
numOfLinks = sel.get_xpath_count('//div[@id="divA"]/a')
random.randrange(1,numOfLinks)
sel.click('//div[@id="divA"]/a[%d]'%random.randrange(1,numOfLinks))
The code above will always click on a random link without having to get the text of the link each time.
精彩评论