How To reuse .getText value in another page Java Selenium - gettext

I am trying to use .getText and want to use that retrieved text, on another page(Search box).
Can I get any help?
I am using Java Selenium.
Thanks
In advance.

You can use the sessionStorage and store the text using getText() add data
to the session storage and it will be accessible to any page from the same site opened in that window.
Update
SessionStorage can store up to approx 5MB of data which will be store on the browser and will be available to the pages which will be open in that tab, It means once you close the tab it will be deleted and not accessible. It expires on the closure of the tab.
String text = driver.findElement(By.xpath("//*[text()='Google offered in: ']")).getText();
WebStorage s = (WebStorage) new Augmenter().augment(driver);
SessionStorage ss =s.getSessionStorage();
ss.setItem("Text", text);
driver.findElement(By.name("q")).sendKeys(ss.getItem("Text"),Keys.ENTER);

Related

How to give a url to the page?

I am trying to open a new window with the below code. It opens a new window but it has the url as "about:blank". How to change the this url and give a custom url.
private native void openPrintWindow(String contents) /*-{
var printWindow = window.open("", "PrintWin", false);
printWindow.document.open("text/html","replace");
if (printWindow && printWindow.top) {
printWindow.document.write(contents);
} else {
alert("The print feature works by opening a popup window, but our popup window was blocked by your browser. If you can disable the blocker temporarily, you'll be able to print here. Sorry!");
}
}-*/;
It is empty, because first parameter of window.open method is an empty string. Check some examples here. So it should be something like this:
window.open("https://stackoverflow.com", "PrintWin", false);
From Your code I see You want to open a new window by custom URL with some HTML content inside. You cannot do it this way. If You put some URL, the browser will try to open this URL by making a GET request.
Solution to what You want to achieve is to do it more-or-less the MVC way (please note it is NOT a fully correct MVC solution, just a guidance):
Before You open the window, You need to store a content somewhere (best option is on a server side, but there is also a way to store it on a client side)
Create a new page, accessible via Your custom URL (either a simple HTML or a service, up to Your needs).
You need to write some code in this new page which will retrieve Your content (stored previously somewhere) and present it in this newly opened window.

How to change multiple Urls at once in Postman?

I have 10+ requests in my Postman collection.
Each time when testing on my local server and testing server I have to change urls from 'localhost:8000' to 'test.mysite' manually.
Is there any solution to change all of them at once ?
You can do this using the 'manage environments' feature - This can be accessed using the icon under the Send/Save button.
Add a new environment file and set the key to 'url' and the value to 'localhost:8000' - make sure you give the file a name before saving. Go back to your request and select the new file in the drop down menu - This will currently say 'No Environment'. Once you’ve selected your file, replace the url string with {{url}}/your-route and hit send. This should now send the local request.
Repeat again but this time add the test server value to the 'url' key. Once that’s in place, all you need to do is switch between the 2 environment files when making requests.
More information about this can be found here https://github.com/DannyDainton/All-Things-Postman/blob/master/Examples/02_createEnvironmentFile.md

Get the current page url inside a hook for contao

I am using the parseArticle hook for news module for my contao instance. I need to get the current page url inside this parseArticle hook. I had checked with the insert tags "{{env::url}}". But it's not working. It is simply displaying this text. Is there any way to use insert tags inside our hook?
If no, what should be done to get the page url inside that hook for contao?
You can retrieve the current URL via \Environment::get('uri'). This also includes the query string.
In general you can also "use insert tags" this way: \Controller::replaceInsertTags('{{…}}'), but this should never be necessary.
If you want the url to the reader page (without the news item in the URL), you can use
global $objPage
$strRelativeUrl = $objPage->getFrontendUrl();
$strAbsoluteUrl = $objPage->getAbsoluteUrl();
Both of these function can take parameters to add to the URL. See PageModel.php#L1013 for example.
Or use
\Environment::get('url');
Found on https://www.marcosimbuerger.ch/tech-blog/contao-environment-klasse-mit-beispielen.html

Sails.js - How to have a unique session for each browser tab

When I run a Sails app from a browser tab I get a unique session in which you can store authentication information. If you start the same application in a different browser tab, the session is identical and is therefore already authenticated. Although useful, I don't want that. I want each browser tab to have a completely unique session. Is this possible and if so, how? How is the sails.sid generated? I thought maybe I could generate a unique secret but of course the time my code gets a look in it is too late.
Obviously I don't have to use req.session at all, and generate my own unique identifier and store for each tab, but want to make use of standard sessions if I can.
You can't have a unique session for each tab in the same browser instance.
The way the session works is not suitable for what you want to achieve.
One solution is to use a socket to identify the tab. Caution, you can not reload the page, cause every time you will get a new socket.
You need dirty hack here.
Every tab has their unique socketId,
So you can use this socketId as a sessionId.
beforeConnect() handle logic for socketId = sessionId & store it somewhere if needed.
afterDisconnect() handle logic for remove session from storage.
NOTE: Tab refresh create new session always because refresh means open
new tab within current tab itself.

GWT dynamic data in new browser window at client side

I've got GWT module where I do some stuff and I have search results - doesn't matter in which form. Now after searching, and clicking on for example "Export to HTML" button,I would like to create new html page (for example from client side code by creating simple string which contains only listed results of searching list of results ) and open it in new browser window. I know that there is Window.open(...) method, but there I must specify url which i don't have. I want to create this new html page by client side - without server inference (I don't want to create some resource on server side and then paste url to this resource to client side). Is there any possibility to achieve this? If there is no option, other method which would satisfy me, is to open standard dialog box for saving, which will allow to save results in a html file.
Thanks for helps.
Kind regards.
Here's the code I use to print:
native void openPrintWindow(String contents) /*-{
var printWindow = window.open("", "PrintWin");
if (printWindow && printWindow.top) {
printWindow.document.write(contents);
printWindow.print();
printWindow.close();
} else {
alert("The print feature works by opening a popup window, but our popup window was blocked by your browser. If you can disable the blocker temporarily, you'll be able to print here. Sorry!");
}
}-*/;
Seems like you could adapt it for your purposes with some simple rewording and by removing the call to print()! The contents variable just holds flat HTML. There are no trips to the server.
openPrintWindow("<h1>Search Results</h1><ol><li>etc...");
The method of opening new window from client js which allows user to save that generated content from browser's save as menu is data:url scheme, content written to opened page via println usualy not saved. But data:url works only in morden browsers. And the content written should be quite small to fit browser's url length resteiction.
See example from this article http://en.wikipedia.org/wiki/Data_URI_scheme#JavaScript