I'm attempting to click the download 'button' in the following image:
As you can see in the inspector, there is extra spacing in the label, so simply doing:
this.clickLabel("Download", "a");
doesn't work.
I've tried cutting and pasting the text from the html, but the nature of the return character producing a parsing error.
Any ideas?
Update:
#Artom B.'s duplicate link does have a potential solution to the problem, but the question being asked by the user is not the same and difficult to find otherwise.
With the help of #Artjom B. I came to use:
var x = require('casper').selectXPath;
casper.click(x("//a[contains(text(), 'Download')]"));
Essentially, the problem of having trailing characters after "Download" is overcome by searching for any link that contains "Download". When utilizing this, be weary that it will cause problems if another link also contains "Download" in the page.
Note: This is similar to the duplicate link Artjom commented on the question, but I think the problem is unique and the title is better related to that problem.
Related
This is a silly question but I can't seem to find an example that works. Basically I want to add a section on my website for the customer to check their USPS Tracking Number Status; USPS only provides an XML API while I need HTML / JS for this to work.
I need to create a text box that takes a 22 character (or less) alphanumeric variable so that when you click a "Submit" button, it will put the variable into this link.
Sadly, I need the entire script code from the and tags. I have tried every example I found and none of them worked in the sandbox, likely because I am missing some basic tags. I have come to the conclusion that I have no clue what I'm doing so please do not get frustrated by the simplicity of my question.
https://tools.usps.com/go/TrackConfirmAction_input?strOrigTrackNum={xxx} where xxx is must be the variable. Every example of code I have found will append to a link, but not put the variable inside the {}. I have been looking and tried a ton of different examples, but being far from a codemonkey I could really use some help. I apologize in advance because I know this is simple but I don't know what I am doing wrong except for trying to do something I have no business trying to do as I'm not a developer. Thanks in advance!
To provide the answer to my own question here us the correct code,
<script type="text/javascript">
function goToPage() {
var page = document.getElementById('USPS_Tracking_Number').value;
window.location = "https://tools.usps.com/go/TrackConfirmAction_input?>strOrigTrackNum=" + page;
}
</script>
Hi I've searched and found different things based loosely around this and some more closely tied but I haven't been able to devise and create a workable solution for the problem I'm having:
Summary:
I am looking to create a view in a specific way due to my requirements. This is currently looking at using a self implemented Treeview style - I don't wish to use any kind of other plugins or pre-made views at the moment, because as you can see by the attached JS fiddle demo at the bottom, I can achieve this myself.
Problem At Hand:
This may be stupidly easy or straightforward and if so please forgive my incompetence but the problem is coming down to the tags - which have text in-between like so:
<ul><checkbox class="collapsible" /><label>Value 1</label>...<ul>
now I have no problem retrieving this values - as there is quite a few in the list of them (one for each option). But finally the base of the problem is matching these to my search input. While I have used the very obvious and generic for each loop it has a problem actually matching the 'input' - my variable for the search input - and the label's text together - hence it wont alert the correct values and can sometimes alert all 15 values when only 4 may match...
Any help would be greatly appreciated with this - feel free to use any of the tree view code which works very nicely alongside the select boxes.
Side note
In my actual view these check boxes will be associated with the label names using an object class to populate the value. Also I want, not really alert the matching labels, but to highlight them - so if anyone could help with that or suggest anything as well that would be nice - not the critical problem though. (sorry i know this is no help or use to you but I thought id enlighten you as to my reasons for alerting these labels.)
MY JS FIDDLE DEMO - TREEVIEW -- EDIT: this was the answer I needed (i will leave it here incase anyone else wants to use this), answer perfectly supplied by Radu Andrei
EDIT: I am not looking to alert based on any criteria asides the fact that the labels text matches the search text.
Answer to the question can be found in the fiddle -> https://jsfiddle.net/mLbhLh89/11/ .
Try as shown in the fiddle
FIDDLE
I just updated your search function with following
$("#search").on("click", function() {
$("label").each(function(i,v){
if($(this).text().indexOf($("#search-criteria").val())>0){
alert($(this).text());
}
});
});
It will find the search string in each label text and show an alert if found.
I've made a simple bookmarklet, to aid with the reading of Daring Fireball.
http://saltcod.github.com/Snowball/
My issue is that the Drag Me Up, Scottie! link doesn't work when you drag it up. If you manually create the bookmark with the same code (https://raw.github.com/saltcod/Snowball/master/snowball.js) it will work, but it won't work if you try and drag it up.
The link is breaking the block of Javascript somehow. Anyone got any ideas as to what I might do with it?
You messed up the quotation marks; your page is NOT valid HTML.
Inside a link, you cannot use ", but either use ' or encode the quotation marks.
Did you not notice that your javascript link was truncated at the first "?
We have a textarea control that holds text and hyperlinks. The links are stored as follows:
http://www.google.com [Link to a site __title__ Title of Link]
http://www.yahoo.com [http://www.yahoo.com __title__ Link with text & hyperlink the same]
In the second link, I don't want to count yahoo twice, so I want to ignore links starting with the left bracket. I know that using Regex to do this isn't the best way, but I don't know of any other way to accomplish this. So far I've tried this regex, but I figured out that Javascript doesn't support lookbehind:
(?<!\[)((http|https|ftp)\://(www\.)?)(([a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9%:/_\?\.'~&=-]*)
Anyone know of a decent way to accomplish this?
I just found out also that I can't rely on the brackets. Users can enter any type of link, using our tool that creates the brackets or by just entering it manually themselves.
Count the number of the character [ in the textarea contents.
The above solution will work, if the format that you have mentioned above persists.
You just need a count? Can't you count all the links then count all the links starting with the left bracket, and subtract?
I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.
The problem is, the few that I have tried don't work very well... For example:
http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"
JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.
Are there any others, or does anyone have recommendations to fix the above two?
EDIT:
This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.
A few to look at, all have working demos:
http://alexgorbatchev.com/SyntaxHighlighter/
http://shjs.sourceforge.net/
http://jush.sourceforge.net/
http://dojotoolkit.org/reference-guide/dojox/highlight.html
use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.