How to copy and paste the content in selenium Webdriver? - selenium-webdriver

Can any one please guide me how I can copy content from one site and migrate to other side with the help of selenium WebDriver ?

Just to be clear, you want to perform an copy/paste of the website directory to another folder ?
Or do you want to parse the html contents, and save that in an external file ?
The former is not really selenium friendly.

So an simple example of what you want is this :
Website 1:
<span id="spanID"> content in here </span>
Website 2:
<form id="inputID"> [ you want content in here ] </form>
Please note the pseudo html.
What you need to do in order to make this work is..
browser.get("http://www.website1.com);
var tempElement = $("spanID");
tempElement .getText().then(function (contentOfSpan) {
console.log(contentOfSpan); // will print the content of the span... now you want to save this value somewhere in your scope.
});
/////////////////////////////////////////////////
browser.get("http://www.website2.com);
var tempElement = $("inputID");
tempElement.sendKeys(RefferenceTocontentOfSpan)

Related

How to access Another Module's Content and Presentation Items after 2sxc v10.20+

Here is code that worked up through 2sxc 10.9.1. Though I am able to get the CmsBlock for the TabID, ModuleID and get that to .Render(), I need more. Here is the old code. Not sure it makes any difference, but this View is using the normal Link content-type and is running in an older version of the Content App (appx 3.03=ish). 2sxc has been upgraded and is now 11.22.0 LTS.
I have removed unnecessary stuff, so I doubt this runs as is...
#using ToSic.Razor.Blade
#using ToSic.SexyContent.Environment.Dnn7
#{
var Helpers = CreateInstance("_Helpers.cshtml");
// Display the items from the Manage Links module, we go in 'sideways'
// this gives us just the Content items with their Presentations settings, etc.
var sxci = Factory.SxcInstanceForModule(3360, 606); // ModuleID of Manage Links
var dyn = Factory.CodingHelpers(sxci);
var allLinks = dyn.AsDynamic(dyn.Data["Default"]);
}
#* other stuff *#
<div class="row co-documents justify-content-center align-items-center">
#foreach (var linkItem in allLinks) {
var linkInfo = Helpers.LinkInfos(linkItem.Link, linkItem.Window, linkItem.Icon);
string iconStyle = linkItem.IconStyle ?? "fas";
int linkColumns = (int)linkItem.Presentation.Columns;
string linkIconAlign = linkItem.Presentation.IconAlign;
string linkIconBGColor = linkItem.Presentation.IconBGColor;
#* other stuff *#
}
</div>
So the easy thing to figure out was how to get the module as a CmsBlock which I can Render() as is (below), but what I need to do instead is get proper access to the List of Content Items AND their Presentation data (like above, allLinks).
ToSic.Sxc.Dnn.Factory.CmsBlock(606, 3360).Render();
What am I missing? How can I get access to the other module's data like I was doing before? In this case, I do this in 3 different places on the website. So to outline this in English, I have a module that the client manages a few special links that get displayed in MegaMenus, other special nav, and directly on a couple of pages. In each place they render differently. In their "home" module, where they get edited, they just look boring like this:
I realize its something like this:
var allLinks = something1.AsList(something2.Data["Default"]);
I understand that something2 is an app instance, but how do I create it in the context of the other module?
And what is something1 nowadays? And how do instantiate it? Looks like its a new ToSic.Sxc.Code.DynamicCode() but I can't figure out how to construct that in a way that I can use or doesn't just throw errors.
Thanks in advance for any insight!!
Okay, it took a little testing, trial and error. And also I missed that DynamicCode() was a Method of the Factory class. In retrospect it does seem easy now.
So first you get the BlockBuilder
var block = Factory.CmsBlock(606, 3360);
Then you get the DynamicCode instance (Code.DnnDynamicCodeRoot) from that
var dc = Factory.DynamicCode(block);
And then things are normal
var allLinks = AsList(dc.Data["Default"]);
The rest of the code works like it did before; I can foreach through the links with Header (renamed from ListContent) and Presentation (now Content.Presentation) working just as expected.
The above answer works fine if you are inside the C# Razor template of the 2sxc View. But what if you are outside, for example in a Razor template for a DDR Menu?
Same two steps as above (get the block and the dc), but then you do NOT have access to AsList() or the App. Thankfully, you already have DynamicCode, so you could just get all the records in the Bibliography content-type like this:
<ul>
var items = dc.AsList(dc.App.Data["Bibliography"]);
foreach (var item in items)
{
<li>#item.EntityTitle</li>
}
</ul>
So once you've got your dc you've got access to all the usual 2sxc toys.

Wordpress addon to add data to a database and then call the data

I know this question is probably going to get downvoted and I will probably get into trouble but I am hoping someone may be able to help me with my situation.
On my site I use json to download data from an external source, and then I style it beautifully.
Within the json data is an individual ID for each data set.
What I want to accomplish is to have a database where I can insert the ID and a url link.
I have created the table within the wordpress database via phpMyAdmin, but I want to create a page within the admin section where I can simply add the data in.
For displaying the json data I use a php insert addon, within that php clip i want to do a piece of code that checks the database for the id within my custom database and displays the link.
I will be honest I don't know where to start on this, even if its just a link to a source that shows me how to create an admin page and submit data to the database within wordpress dashboard.
I really appreciate any help given and like I say I know I should try harder, but when ever I do a search all I get is 100's of references to add an admin to the database manually.
Thanks,
Adam
Edit I just realized I never put any table information in my question.
The table name within wordpress is called: wp_home_tickets
within that are 3 fields: id (auto increasement), gameid (numeric) and ticketlink (text)
thanks.
For adding a custom settings page in your admin, use the Settings API https://codex.wordpress.org/Settings_API
Here is a nice tutorial using it https://deliciousbrains.com/create-wordpress-plugin-settings-page/#wp-settings-api
To fetch data from your custom table, use the wpdb class https://developer.wordpress.org/reference/classes/wpdb/. More specifically, you can use wpdb::get_results if you will have multiple rows sharing the same id https://developer.wordpress.org/reference/classes/wpdb/get_results/
Or wpdb::get_row if you will ever only have one https://developer.wordpress.org/reference/classes/wpdb/get_row/
Hope this helps you out!
For anyone wishing to see how it was done, here is how I did it.
I created a file in my theme called db_admin_menu.php and added the following to it:
<?php
function ticket_admin_menu() {
global $team_page;
add_menu_page( __( 'Tickets', 'sports-bench' ), __( 'Tickets', 'sports-bench' ), 'edit_posts', 'add_data', 'ticket_page_handler', 'dashicons-groups', 6 ) ;
}
add_action( 'admin_menu', 'ticket_admin_menu' );
function ticket_page_handler() {
$table_name = 'wp_home_tickets';
global $wpdb;
echo '<form method="POST" action="?page=add_data">
<label>Team ID: </label><input type="text" name="gameid" /><br />
<label>Ticket Link: </label><input type="text" name="ticketlink" /><br />
<input type="submit" value="submit" />
</form>';
$default = array(
'gameid' => '',
'ticketlink' => '',
);
$item = shortcode_atts( $default, $_REQUEST );
$gameid = $item['gameid'];
if ($wpdb->get_var("SELECT * FROM wp_home_tickets WHERE gameid = $gameid ")) { echo 'Ticket already exists for this game.'; goto skip; }
if (!empty($_POST)) { $wpdb->insert( $table_name, $item ); }
skip:
}
?>
I then put this code in my script that fetches and displays the json:
$matchid = $match['id'];
$ticket_url = $wpdb->get_var("SELECT ticketlink FROM wp_home_tickets WHERE gameid = '$matchid' ");
if ($ticket_url) { echo 'Get Tickets'; }
I hope someone does find it of use, i did have to use a wordpress plugin called `Insert PHP Code Snippet' by xyzscripts to be able to snippet the php to a shortcode, but that is not the purpose of this post.
Thanks again for your help.

how can I load a joomla module as a link?

this is my problem...
I have some of images and links that I want to load different joomla modules when user click on them.
mean each hyperlink can load another module|position
thanks all
In case that you just want to call a module's content from a url the following answer will help you.
If you just want to show / hide a module in the same page you could use something similar to my previous answer: Joomla 3 Show different modules on same position depending on toggler
Joomla provides the functionality to call a specific file of the active template by adding the tmpl=FILENAME key/value to the url's query string.
All built-in templates have a component.php file if user wants to load the template with the component only. You could check the following link for more details: Adding print pop-up functionality to a component.
You could do something similar to only show the modules that you want to load.
You could copy the component.php to a new file (I have used custom.php) and added the following php code in the <body> ... </body> part.
<?php
$jinput = JFactory::getApplication()->input;
$selectedPosition = $jinput->getString("position", "");
$selectedModule = $jinput->getString("module", "");
$selectedModuleTitle = $jinput->getString("title");
if($selectedPosition !== "") {
$modules = JModuleHelper::getModules($selectedPosition);
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module);
}
} elseif ($selectedModule !== "") {
$module = JModuleHelper::getModule($selectedModule, $selectedModuleTitle);
echo JModuleHelper::renderModule($module);
}
?>
So with a similar way as loadposition / loadmodule works you could call the new template file using:
index.php?tmpl=custom&position=MODULE_POSITION
or
index.php?tmpl=custom&module=MODULE_TYPE
or
index.php?tmpl=custom&module=MODULE_TYPE&title=MODULE_TITLE
Optionally if you want to load the module with a specific style, you could pass it to the second paramter of the renderModule method like:
echo JModuleHelper::renderModule($module, array("style" => "xhtml"));
Hope this helps

Links in strings - Typescript

I'm working at a project written in Ionic/Angular/Typescript. In the .html file, I have
< p> {{stringVar}} </p>
In the .ts file,I have
this.stringVar= "Visit http://www.google.com.
Visit http://www.stackoverflow.com."
I have 2 questions:
1) I want the 2 sentences in the string to be displayed in html on different lines. What should I do in order to achieve this: add \n or < br> or something like this?
2) I want the 2 links in the string to appear as links in html,too. That is,when the user clicks on them,he will be taken to those sites.
Thanks in advance!
1) To appear in different lines, you must put each one inside their own <p> tag, like this:
<p>first line</p>
<p>second line</p>
2) To appear as clickable links, you need to put in <a> tags, with url in href attribute, like this:
<p>click here to visit google.</p>
It would be better if you could change the structure of your data, to something like this:
<p ng-repeat="url in urlList">Visit {{url}}</p>
this.urlList = [
"http://www.google.com",
"http://www.stackoverflow.com"
];
or even better:
<p ng-repeat="site in siteList">Visit {{site.name}}</p>
this.siteList= [
{ name: "Google", url: "http://www.google.com" },
{ name: "StackOverflow", url: "http://www.stackoverflow.com" }
];
The best approach to go with a 'list', rather than a stringVar
this.linkList = [
"http://www.google.com",
"http://www.stackoverflow.com"
];
1) I would suggest to have <p></p> instead of <br/> in between.
2) The following is a working sample with Angular2
<p *ngFor="let link of linkList">Visit {{link}}</p>
Check the working sample here : https://embed.plnkr.co/Om3CXpT9xN07YCz2aHQr/
Both Question has one answer you Basically want to Interpolate string with html in the angular, although i am not expert in angular1.x but yes there is one service used for the same called as
$interpolate(templateString)(you_.ts/js_code);
by using this you can show your string as it as on the webpage event using html in you javascript file too. you just have to pass the html in your string ans display it in the webpage
for example lets assume your use case you simple have to add this like :-
this.stringVar= "Visit <a href='http://www.google.com'>Google</a> Here and<br> Visit <a href='http://www.stackoverflow.com'>Stackoverflow</a> Here."
and than convert this using interpolate like this
$scope.your_string = $interpolate(templateString)(stringVar);
Working Example for the same

How to reuse Loop ? get_template_part() or?

I want to use the same Loop and Pagination for
index.php , search.php , and archive.php
However, for search.php I want a title "Search Results" to appear before the Loop
and for archive.php I want a title "Archive Page" to appear before the Loop.
Method A
Keep index.php, search.php, and archive.php
And use get_template_part() for navigation and Loop ?
Method B
Just use index.php
but how?
Or is there a simpler method since all I want is to add a title before the Loop?
Simple code for the sake of this example:
index.php
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_excerpt();
endwhile; endif;
?>
code for Pagination
search.php
<h2>Search Results</h2>
code for The Loop
code for Pagination
archive.php
<h2>Archive Page</h2>
code for The Loop
code for Pagination
I don't know the exact structure of your pages, but I would place the code in header.php. Here is my thought on this
The header is common to all of these templates, and I would suspect that you are going to need these titles between your header stuff and the content area
Target pages with conditional tags . Open your header, and right down at the bottom, add something like this
if(is_search()) {
//your title for search page etc
} elseif(is_archive()) {
//your title for archive page
} else {
//display nothing if you don't need to display any custom title
}
Just add the necessary mark up and style accordingly
EDIT
It seems that you are still very new to php. From your comment
Weird. I put <?php if(is_search()) { <h2>Search Results</h2> } ?> at very bottom of header.php but got White Screen. So instead, I put it in index.php and deleted search.php but still White Screen. I tested it in my theme and Twentytwelve. ---------- Can you help me understand... Does less php files equal to a faster website? Is reducing the amount of php files considered best practice? So if index.php , search.php , archive.php uses the same code except for a title "Search Results" and "Archive Page" - is it best practice to simply have one php file and do conditional statements for titles?
Your problem is switching between php and html elements. Whenever you switch from php to html, you need to close your php tag (?>)before your html element. On the otherhand, you need to open a new php tag (<?php) right after your last html element and before your first php element.
Not doing this correctly will lead to a synatx error, which causes a white screen of death.
So in short, your code will need to look like this for it to work properly. Note the php tags
<?php
if(is_search()) { // this part is php
?> <!-- Close php because whe're switching to html -->
<h2>Search Results</h2> <!-- this part is html -->
<?php // open new php tag as we're switching to php again
} elseif(is_archive()) { //same sequence above applied
?>
<h2>Archive Page</h2>
<?php
} else {
//display nothing if you don't need to display any custom title
}
?>
Less php files does not mean a faster website, speed is determined by content, content type, database queries, amount of queries, etc etc. A one page website can be slower than a 10 page website.
What I've done with this code and why I placed it in the header is just to keep the code together. You can split it up as you wish. There is no best practice. What really counts is readability, accesibility, not repeating code over and over, and keeping a proper file system
You could output the title before you start the loop. The contents of the loop would be called using get_template_part(). For example:
if ( have_posts() ) {
// Output the title.
the_title();
// Begin loop.
while ( have_posts() ) {
the_post();
get_template_part( 'loop', 'index' );
}
}
Update: Using just index.php to display a title conditionally, you would do this:
if ( is_search() ) {
// Display the search page title here.
} else if ( is_category() ) {
// Display the category title here.
}
Ref: http://codex.wordpress.org/Function_Reference/get_template_part

Resources