What Xpath expression can I use to find all the anchor (just 'a') elements whose actual text (the innerHTML) is Logout.
something like
//a[#innerHTML='Logout']
Would that be correct?
No, it would be incorrect. innerHTML is a property, part of the object model, while XPath operates on tags and attributes. Unless your a tag actually has an attribute named innerHTML, this wouldn't work.
If you want to compare the value of the tag itself, you can use the . (dot) to refer to the tag:
a[.='Logout']
However, I must add, just in case you're using jQuery: I'm not sure if it will work with jQuery. jQuery does not support XPath fully, only basic stuff.
Related
I am a beginner to xpath and I am unable to get XPath to get link from 'a' tag for below HTML code.
Get HREF value where span class value is "Upholstered" as shown in the snapshot.
Here, I want this value "/furniture/Bedrooms/Queen-Beds/_/N-8ddZ1z141u9?qf=styles_Upholstered" using Xpath.
Can you help me out please
According to your description the relevant XPath query to Get href value where span class value is "Upholstered will be something like:
//a[#class='Upholstered']/#href
However you forgot to add your actual HTML code (at least partial) so the above answer might not be 100% accurate.
Reference material:
XPath Language Specification
XPath Tutorial
Using the XPath Extractor in JMeter
Use below xpath to extract the URL of your <a> tag
//ul[#class='facetOptions']/li/a[#role='checkbox']/#href
So I was wondering if there is a way to find the element that belongs to a specific String that you know exists on a HTML page as part of an attribute. The example is I know that "Apr-16-2015" is somewhere in an attribute on the HTML page. If I go look for it, it's part of the attribute title:
<a title="Apr-16-2015 5:04 AM"
However, I do not have the information about the exact time, i.e. the "5:04 AM". I was wondering if there is a way to partially search an attribute in order for it to return the full element.
This is my code:
org.jsoup.nodes.Element links = lastPage.select("[title=\"Apr-16-2015\"]").first();
Again, it doesn't work because I did not enter the full attribute title, as given above. My question: "Is there any way to make this selector work by not entering the full information, as I will be unable to have the latter part of the attribute to my disposition?"
You can use it in the following way:
lastPage.select("[title^=\"Apr-16-2015\"]").first();
As described on JSoup Documentation:
[attr^=value], [attr$=value], [attr*=value]: elements with attributes
that start with, end with, or contain the value, e.g. [href*=/path/]
References:
http://jsoup.org/cookbook/extracting-data/selector-syntax
I understood that in the newer Polymer release 0.8 binding to an attribute inside a tag should be followed after $ sign. And it works like so:
<tag attribute$="{{DATA}}">
e.g. this works great:
href$="{{url}}"
But it doesn't work when the attribute gets more complex, e.g. in my code example:
<a style$="background-image: url({{backgroundimage}});">
which is a String data attribute.
Is it supported in 0.8 like it was in 0.5 ?
Complex bindings like that are not currently supported in 0.8. Instead you'd probably want to create a computed property and use that.
Btw, you only need to use $={{ }} syntax if you need work with an attribute that doesn't have a corresponding property on an element. Because HTMLAnchorElement (the <a> tag) has an href property, you don't have to use a dollar sign in that case, you can just create a regular binding using href={{url}}.
To put it another way:
href="{{site}}" means "bind this.site to element.href"
href$="{{site}}" means "bind this.site to element.attributes.href.value"
You usually only need the $ syntax when working with boolean attributes like hidden or disabled. Or in the case where an element does not have a corresponding property in JavaScript.
I have seen this code from the tutorial that I'm studying. I searched for the purpose of the p attribute inside the li tag but found no answer. What is the purpose of that p attribute inside the li tag?
$msgs .= "<li p=\"$no_of_paginations\" class=\"inactive\">Last</li>";
The purpose cannot be inferred from the code snippet. As such, the attribute, being not defined in any HTML specification or draft or browser-specific extension, has no effect beyond being stored as data into the p element node in the document tree.
Such an attribute, though invalid by the specs, can be used like any other attribute in styling (e.g. attribute selector .p) in CSS or in scripting. In this case, it is probable, but by no means certain, that the attribute is meant to be used in scripting to carry a number as its value, with that number inserted with some server-side code, so that this value can be accessed in client-side scripting, as relating to a specific element.
The recommended way is to use data-* attributes instead, such as data-p, to avoid any risk of clashing with attribute names that might be introduced in some future HTML version.
The default HTML(whichever version) namespace doesn't have a purpose for "p" inside a li tag. If there's another namespace declared then that's where it's from. Other than that, it's not valid by w3 standards.
It should be a custom attribute to use in JavaScript codes to get something.
That is just a custom tag used in some javascript functions
I have a'a' tag, something like this:
How can i put a link inside the data-description tag, so that i have a link inside a description link.
You can just write a tag there, e.g.
...
The value of an attribute is parsed as plain text, except for character/entity references, so the less than character < is just another data character.
Nothing inside a data-* attribute value is parsed as a tag, but that’s a special case of the fact that it is unspecified text. All use of such attributes is by definition dependent on what you do in your page or application. So if you need something to be interpreted as tags, just write the processing so that they will be so interpreted.
You cannot nest tags inside of tag attributes.
You can refer to this: Link inside a div link