Forum Discussion
ArtemS
Alumni
14 years agoHi Vince,
Once the destination of a link is set during the on-page routine execution, there's no way to read it, except for running this or a similar on-page routine. TestComplete can call routines from web pages, but it does not have access to the internals of these routines.
You may insert a helper function into the web page's HTML that would calculate the target location of the download link in the same way as the download_clicked function does, and return the destination as a result.
Then, during the test, you can call this web page function from TestComplete (as described in the Calling Scripts Located on a Web Page From TestComplete Scripts topic) and store its result:
A workaround is to analyze the content of the parent page. In the HTML code you provided, the link text says "Download for Windows", hence, the page has some sort of an on-load event that checks the current platform and modifies the link caption. Thus, you can analyze this caption and calculate the link destination on TestComplete's side:
Regards.
Once the destination of a link is set during the on-page routine execution, there's no way to read it, except for running this or a similar on-page routine. TestComplete can call routines from web pages, but it does not have access to the internals of these routines.
You may insert a helper function into the web page's HTML that would calculate the target location of the download link in the same way as the download_clicked function does, and return the destination as a result.
function getlocation(){
...
if (platform == 'mac') { return 'https://192.168.0.1/download/mac.pkg'; }
if (platform == 'linux') { return 'http://192.168.0.1/products/latest.bin'; }
if (platform == 'windows') { return 'https://192.168.0.1/download/win.exe'; }
Then, during the test, you can call this web page function from TestComplete (as described in the Calling Scripts Located on a Web Page From TestComplete Scripts topic) and store its result:
...
LinkTarget = page.Application.Document.Script.getlocation();
...
A workaround is to analyze the content of the parent page. In the HTML code you provided, the link text says "Download for Windows", hence, the page has some sort of an on-load event that checks the current platform and modifies the link caption. Thus, you can analyze this caption and calculate the link destination on TestComplete's side:
...
LinkCaption = page.Panel("download_but").Panel(0).Link(0).innerText;
switch (LinkCaption)
{
case "Download for Windows":
{
LinkTarget = "https://192.168.0.1/download/win.exe";
break;
}
case "Download for Macintosh":
{
LinkTarget = "https://192.168.0.1/download/mac.pkg";
break;
}
case "Download for Linux":
{
LinkTarget = "http://192.168.0.1/products/latest.bin";
break;
}
}
...
Regards.