Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I visit dynamic URLs other than hacking https:// and http:// steps? - Example of defining custom functions by users for their use cases #236

Closed
kensoh opened this issue Jul 7, 2018 · 7 comments
Assignees
Labels

Comments

@kensoh
Copy link
Member

kensoh commented Jul 7, 2018

user query


Something simple, I can do it a long way, but just want to see if there's a better way to do this in TagUI.

Suppose I grabbed a url from a page using:

read //a/@href to url

Then I want to go to that page to grab the details from that page.

Suppose url = https://google.com

Since url is a variable, I tried

'+url'+

It gives the error message: ERROR - cannot understand step '+url+'

Using the long way I can do this. One for https://
url = url.replace(/https:///g, "");
https://'+url+'
Another for http://
url = url.replace(/http:///g, "");
http://'+url+'

I tried the following - so that it can handle both http:// and https://. But it didn't work:
url = url.replace(/https:/g, "");
https'+url+'

For your advice, please.

@kensoh kensoh added the query label Jul 7, 2018
@kensoh kensoh self-assigned this Jul 7, 2018
@kensoh
Copy link
Member Author

kensoh commented Jul 7, 2018

@Aussiroth's reply


The issue here is that TagUI determines if the step is to load a URL or not by doing the following 3 steps - if the line starts with http://, or https:// or about:blank.

So if you try to use something like '+url+' without those at the start TagUI can't interpret that you definitely want to go to a URL since it doesn't know what the variable content is (at the PHP processing part). Previously my method was similar to yours in that I would manually perform a https://'+url+' to go to the url in tagui.

Perhaps Ken will have some further ideas on this.

@kensoh
Copy link
Member Author

kensoh commented Jul 7, 2018

user's reply


Thanks for the explanation!
"So if you try to use something like '+url+' without those at the start TagUI can't interpret that you definitely want to go to a URL since it doesn't know what the variable content is (at the PHP processing part)" => yes, this makes perfect sense.

Since you can test for "line that starts with http://, or https:// or about:blank"

Is it possible to add one more: "line that starts with http://, or https:// or about:blank OR gotourl"

If there's a gotourl, we can then do a
gotourl '+url+'

without the need to do a convoluted way of removing and adding back the http:// and http://
One for https://
url = url.replace(/https:///g, "");
https://'+url+'
Another for http://
url = url.replace(/http:///g, "");
http://'+url+'

For your consideration, please.

@kensoh
Copy link
Member Author

kensoh commented Jul 7, 2018

my reply


Try this. TagUI v4.0 will look for a tagui_local.js file in same folder of script and tagui_global.js in tagui\src folder for user-defined custom functions. Below example shows the custom function gotourl defined and used.

demo.txt

https://google.com
yahoo_url = 'https://yahoo.com'
gotourl(yahoo_url);
wait 3 seconds
echo url() ' - ' title()

tagui_local.js

function gotourl(link) { // this custom function goes to the url provided
        casper.evaluate(function(link) {window.location.href = link;}, link);
}

output

START - automation started - Sat Jul 07 2018 12:40:46 GMT+0800 (+08)
https://google.com - Google

wait 3 seconds
https://sg.yahoo.com/?p=us - Yahoo

https://sg.yahoo.com/?p=us - Yahoo
FINISH - automation finished - 7.9s

@kensoh kensoh changed the title How do I visit dynamic URLs other than hacking https:// and http:// steps? How do I visit dynamic URLs other than hacking https:// and http:// steps? - Example of defining custom functions by users for their use cases Jul 13, 2018
@kensoh
Copy link
Member Author

kensoh commented Jul 13, 2018

decided to not implement this as a new step. because it can go down the rabbit hole to include back step to go back to the previous page and many other new steps. will let users who need something like this implement by writing their own user-defined functions in tagui_local.js or tagui_global.js

going to update readme documentation with reference to the example above - #236 (comment)

@pallavkrishna
Copy link

how to get url for newly launched tab.

I have a scenario i need to click on a link which will opens a new tab. i want to get the url of newly launched tab.

can any one help me

@kensoh
Copy link
Member Author

kensoh commented Apr 9, 2019

Hi Pallav, from #392 I see you mean getting the URL of the updated webpage URL.

You can use the url() helper function to do that -

https://github.com/kelaberetiv/TagUI
click //*[@id="readme"]/div[2]/article/p[7]/a
echo url()

For a list of other useful helper functions, see https://github.com/kelaberetiv/TagUI#helper-functions

@pallavkrishna
Copy link

hi Kensoh
url() returns parent tab url but i need the url of newly launched tab.
please find the example
1.http://demo.guru99.com/popup.php

2.click //a[text()="Click Here"]

3.echo url()

in step 3 it is returning the launched url (http://demo.guru99.com/popup.php) but when i perform step 2 a new tab will be opened so i need the what url is launched in step 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants