source = self.webdriver.page_source
download_url = re.findall("\"(http[^\"]+action=download)\"", source)[0].replace("\\","")
This is able to get the download link for the first file, but when the presentation goes to the next file, the download link is updated using JavaScript, so using the page source will no longer work.
Talk to your devs and find out what the button is doing.
I suspect it’s performing a POST and the file that is downloaded is the response to the post. If this is the case you just need to know what the POST criteria are and you can programmatically send a POST yourself. I have an update to the file downloader code I originally wrote to allow you to select the request type (e.g. GET, POST, PUT, etc.) but I haven’t pushed it yet (I’ll update the thread when I do, the code is on another machine at the moment).
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/aVTStVrN66YJ.
For more options, visit https://groups.google.com/groups/opt_out.
Getting hold of listeners is hard, you can do it in jQuery if the listener was registered in jQuery, here’s some groovy code(It should be easy enough to read if you understand Java)
I need to remember to turn it into proper Java and stick it on my blog.
To get all the listener’s registered on an element (only listeners that have been added using jQuery remember):
((JavascriptExecutor) driver).executeScript("return jQuery._data(jQuery(arguments[0]).get(0), 'events')", element) as Map<String, Object>
You can then turn this into an additional condition if you want to wait for listeners to be registered (not really applicable to your problem, but possibly useful none the less):
public static ExpectedCondition<Boolean> listenerIsRegisteredOnElement(final String listenerType, final WebElement element){
new ExpectedCondition<Boolean>() {
@Override
Boolean apply(WebDriver driver) {
Map<String, Object> registeredListeners = ((JavascriptExecutor) driver).executeScript("return jQuery._data(jQuery(arguments[0]).get(0), 'events')", element) as Map<String, Object>
for (Map.Entry<String, Object> listener : registeredListeners.entrySet())
{
if(listener.getKey().equals(listenerType)){
return true
}
}
return false
}
}
}
If you aren’t using jQuery to register listeners then all bets are off, there is no generic way to find out what listeners are applied to an element in JavaScript (if I’m wrong please let me know, but I haven’t found one yet, everywhere says it is not possible).
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/fNxrRk2e3VUJ.
What do you actually do with that file?
How do you know the file has finished downloading?
How do you know the name of the file (especially if one with the expected name already exists, do you cater for this?)?
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Nick
Sent: 01 April 2013 23:37
To: seleniu...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/qBeFUOIYwvsJ.
I’m totally aware, that’s why I wrote this blog post:
What I’m trying to do is make you think about what your test is actually validating if you just set up a FireFox profile to download everything to disk. If your answers to the three questions I posed are:
1. Nothing.
2. I just hope it’s finished downloading when I access it.
3. I assume it is the same as the name of the file in the href I clicked on.
Then I would suggest that actually doing the download in the first place is a completely pointless exercise that does not test anything and is only slowing your tests down and wasting disk space.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/eg2HNSZu6OwJ.
So my next questions are:
· How are you validating that the file is the same as the one on the server?
· Why does the filename matter?
· How do you know you have downloaded a new file?
Before disagreeing with the blog post you should read it. It doesn’t say that you should never do download tests, it questions why you are doing them and tries to get you to think about what your tests are actually testing.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/9XkGKsEI6a0J.