I want to get driver.get from a partial url so for example:
usually we do this:
driver.get('www.dummy.com/event/rocknroll/1234')
but now I dont know the event name so is there any way I can do something like this:
driver.get('www.dummy.com/event/*/1234')
Thanks
As per my understanding this will not work, as the get method expects a string as the parameter.
From docs,
void get(String url);
/**
* Get a string representing the current URL that the browser is looking at.
*
* #return The URL of the page currently loaded in the browser
*/
However, have you tried hitting the url with some dummy tests for this?
Related
As I've to use csrf in my grails application, I'm doing it by encapsulating my action logic under withForm{...}.invalidToken{....}, also I'm adding an attribute as: g:formRemote useToken="true" under g:formRemote tag in gsp.
The problem is, I'm always getting inside the invalidToken{...} block on submit and hence my form is not getting saved.
How should I make it working properly?
Example:
def action = {
withForm{
......
}.invalidToken{
println "Invalid Token code"
}
}
gsp ex:
<g:formRemote useToken="true" ...>
...
...
</g:formRemote>
useToken is not supported with formRemote. Please take a look on https://github.com/grails/grails-core/blob/2.5.x/grails-plugin-gsp/src/main/groovy/org/codehaus/groovy/grails/plugins/web/taglib/JavascriptTagLib.groovy#L349
The supported attributes for formRemote are:
* #attr name REQUIRED The form name
* #attr url REQUIRED The url to submit to as either a map (containing values for the controller, action, id, and params) or a URL string
* #attr action The action to execute as a fallback, defaults to the url if non specified
* #attr update Either a map containing the elements to update for 'success' or 'failure' states, or a string with the element to update in which cause failure events would be ignored
* #attr before The javascript function to call before the remote function call
* #attr after The javascript function to call after the remote function call
* #attr asynchronous Whether to do the call asynchronously or not (defaults to true)
* #attr method The method to use the execute the call (defaults to "post")
With that said. You can keep using the withForm in your controller and implement the form submission using jQuery or other JS library and send the token. Please take a look at this question: Grails - Is there a recommended way of dealing with CSRF attacks in AJAX forms?
Also I would recommend you to move on from tags like formRemote. I'm assuming you're using at least Grails 2.x. In case you want to migrate to Grails 3.x in the future, the Ajax-related tags are deprecated.
Hope this helps.
Let's say I want to get a zip file (and then extract it) from a specific URL.
I want to be able to use a wildcard character in the URL like this:
https://www.urlgoeshere.domain/+*+-one.zip
instead of this:
https://www.urlgoeshere.domain/two-one.zip
Here's an example of the code I'm using (URL is contrived):
import requests, zipfile, io
year='2016'
monthnum='01'
month='Jan'
zip_file_url='https://www.urlgoeshere.domain/two-one.zip'
r = requests.get(zip_file_url, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall()
Thanks in advance!
HTTP does not work that way. You must use the exact URL in order to request a page from the server.
I'm not sure if this helps you, but Flask has a feature that works similarly to what you require. Here's a working example:
#app.route('/categories/<int:category_id>')
def categoryDisplay(category_id):
''' Display a category's items
'''
# Get category and it's items via queries on session
category =session.query(Category).filter_by(id=category_id).one()
items = session.query(Item).filter_by(category_id=category.id)
# Display items using Flask HTML Templates
return render_template('category.html', category=category, items=items,
editItem=editItem, deleteItem=deleteItem, logged_in = check_logged_in())
the route decorator tells the web server to call that method when a url like */categories/(1/2/3/4/232...) is accessed. I'm not sure but I think you could do the same with the name of your zip as a String. See here (project.py) for more details.
there
In my application, if someone pass a parameter on the URL I want to do different things on the template.
I know I can get on server side a query string using this.params.query but how can I pass it to client OR get this value on client-side?
In my case I will send an optional redirect on the URL, and if it was passed, after the main task, my app will redirect the user to the url given. But I just know how to see redirect on server side, not on client, so this information get lost when I, for example, submit a form
Could you help me?
You can access the router params in your template with:
Router.current().params.query
Maybe in your route you can do like this:
onBeforeAction: function() {
Session.set("query", this.params.query);
this.next();
},
Then somewhere on the client you can make a helper like this:
Template.yourTemplateName.helpers({
query: function() {
return Session.get("query");
}
});
I'm not sure what to do with your redirect, but maybe it will work in the helper. So your html would be something like:
{{#if query}}{{query}}{{/if}}
And in the helper you could possibly replace "return Session.get("query")" with something like "Router.go('/wherever-you-want-to-go');". Or just write another helper to run in your html if the query is positive.
Is there a way to get the FULL URL loaded by a WKWebView for every request?
webView:didFinishNavigation:
Works only for mainFrame navigations and does not provide a URL request parameter.
How do I get the FULL URL just like in UIWebViewDelegate's
webViewDidFinishLoad:webView
...which gets invoked after any loading finishes and you can get the full request URL from the webView parameter.
It's nice that WKWebView's URL property saves the work that needs to be done to extract a UI-friendly base URL, but it's a huge loss we can't get the full one!
I have tried using
webView:decidePolicyForNavigationAction:decisionHandler:
...but it produces different results for URLs compared to what a UIWebView's request property holds after finishing the load of a page.
You can get URL for a newly requested Webpage by "navigationAction.request.URL" in decidePolicyForNavigationAction delegate method.
func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
if let urlStr = navigationAction.request.URL?.absoluteString{
//urlStr is what you want, I guess.
}
decisionHandler(.Allow)
}
First, I think you are confusing NSURL and NSURLRequest. The first is readily accessibly via webView.URL and it does actually give you the full URL of whatever was loaded. Assuming that where you say URL you mean NSURL.
If that is not what you meant, for example if you wanted to see the redirect chain or the response headers, then I'm afraid the answer is that you cannot get to tht specific information via the WKWebView.
You will have to fall back to UIWebView where you can intercept requests relatively easily and see the full request/response.
This is Yuichi Kato's answer for Swift 4. It retrieves the full URL from the request property of the navigation action in the webView(_:decidePolicyFor:decisionHandler:) method of WKNavigationDelegate.
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: #escaping (WKNavigationActionPolicy) -> Void) {
if let urlStr = navigationAction.request.url?.absoluteString {
//urlStr is what you want
}
decisionHandler(.allow)
}
Don't forget to conform your class to WKNavigationDelegate and set your web view's delegate accordingly:
class WebViewController: UIViewController, WKNavigationDelegate
[...]
webView.navigationDelegate = self
I'm trying to access the base url of my site inside a command action like this:
namespace Vendor\TxTest\Command;
class TestCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
{
/**
* logger
*
* #var \TYPO3\CMS\Core\Log\LogManager
*/
protected $logger;
/**
* Class constructor
*/
public function __construct()
{
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Core\\Log\\LogManager' )->getLogger( __CLASS__ );
}
/**
* Test command
*/
public function testCommand()
{
$homeUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl( '/' );
$this->logger->info( 'url: ' . $homeUrl );
$this->logger->info( "\n\r\n\r" );
}
}
When I run the command from the Scheduler backend module, the domain looks ok, but when it runs automatically, the result is:
Mon, 10 Mar 2014 ... component="Vendor.TxNews.Command.TestCommandController": url: http:///
What is the correct way to get the domain in this context?
PHP knows the domain from the server-call. If your site is on a specific server, you might have several urls pointing to this server. Your PHP does not know by itself which domain he has. Only from the request that the user is doing PHP is getting this information in the $_SERVER-var that Typo3/Extbase can read. I assume your script is running on different servers if you want to get the url? Can you put a configuration on the server that is different for each server?
One approach to do this would be to store the url from a user-call and read this in your Background-Module.
to put it clear: If you run the scheduler automatically and therefore trigger PHP in CLI mode, there is no request URL / it is empty, as like the name already suggests u run in command line interface mode.
Typoscript has the baseURL settable and switchable, but even there the domain of the call is undefined, which is perfectly right.