10

My test page contains a link with onclick making an ajax call as follows

 <a title="test delim" alt="" 
onclick="$find('MetricsReport').exportData('TAB');"
 href="javascript:void(0)" 
style="color: rgb(50, 50, 50); . . . ">Click to download</a> 

When the above link is clicked, a report get downloaded to default download location.

I'm testing it with java selenium

 ((JavascriptExecutor) driver).executeScript("$find('MetricsReport').exportData('TAB');"); 

It works fine with ChromeDriver, but doesn't work with PhantomJSDriver . No error is thrown. It kindof executes but nothing happens. The report is not downloaded

How can I make it work with PhantomJSDriver?

john
  • 647
  • 5
  • 23
  • 53
  • Did you try to get the element `driver.findElement("xpathOfElement")` and then make an `element.click()`? Maybe this is a more realistic test which mimics the user interaction?! – kism3t Jun 07 '17 at 05:25
  • This does not work either. – john Jun 08 '17 at 04:40
  • Clicking does not seem to be a trivial task in PhantomJS, check out this question https://stackoverflow.com/questions/15739263/phantomjs-click-an-element – Jesko R. Jun 15 '17 at 22:25

1 Answers1

2

Please have a look on this question. This might solve your problem.

How to download a csv file using PhantomJS

You can make AJAX call to download and encode your file, then you can return this content back.

Ankur
  • 893
  • 3
  • 12
  • 29
  • Thank you. I'm not sure how to implement that example. Where do I need to plug `$find('MetricsReport').exportData('TAB');` ? Do I need to replace `$ajax . . .` with `$find` ? I'm confused because that example relies on the direct donload link `http . . . csv` which i dont have. A report on my test page downloads with the `$find` command – john Jun 11 '17 at 18:45