I would like to know if it is possible to create a link to a specific span in someone else's page. For putting on a website or blog one might create for themselves, or even a local page one uses to put links to something interesting they found maybe.To be more clear, I want the link this way so that when someone clicks on the link, it goes to a specific location on the page, mostly for a long page where you want someone to go directly to the relevant information - when that part of the page doesn't have an anchor element you can make use of. I am using Wikipedia as an example, even though it might not be the best example, because I know Wiki uses it's own way of doing certain things. Say you wanted to link to the Wiki page "List of fallacies" and the span for the sublist titled "Red herring fallacies".
The page link is :
"https://en.wikipedia.org/wiki/List_of_fallacies"
Using Inspect Element, I got this for span :
<span class="mw-headline" id="Red_herring_fallacies">Red herring fallacies</span>
I tried to combine them like this :
<a href="https://en.wikipedia.org/wiki/List_of_fallacies<span class="mw-headline" id="Red_herring_fallacies">Red herring fallacies</span>">Red
herring logic fallacies list</a>
I am just wondering; am I a) doing it incorrectly for just using HTML, b) it can be done, but you have to use additional assets (CSS, JavaScript, etc), or c) it isn't possible to do at all?
I would like to do it using just HTML if possible, but if that is not possible, then I would appreciate it if someone can tell me how you might do it some other way - if it isn't impossible altogether. Thanks
Edit: My page is marked as a duplicate of answers to an earlier question, and from looking at the page it appears that this IS true. But I think my question heading itself was more clear to a beginner without much knowledge of advanced topics in creating webpages. Thanks for all of the help, and if the moderator believes my point is not relevant then please feel free to do whatever you do with duplicate questions.
you are missing a close "> just before the span started and you are missing the anchor in your href like this #Red_herring_fallacies, because span has that ID
<a href="https://en.wikipedia.org/wiki/List_of_fallacies#Red_herring_fallacies">
<span class="mw-headline" id="Red_herring_fallacies">Red herring fallacies</span>
Redherring logic fallacies list
</a>
The span has an ID. Use that as the parameter in your URL in the link.
Red herring logic fallacies list
To target an id you must add #theId at the end of your url.
The result will look ass follow:
<a href="https://en.wikipedia.org/wiki/List_of_fallacies#Red_herring_fallacies">
Red herring logic fallacies list
</a>
Related
I have hundreds of footnotes in scores of documents.
All are in HTML4 format. I have needed to update all the pages to HTML5.
When using a code checker for HTML5, I am informed that "NAME" as be deprecated and it I am getting warnings in to change the code.
I can't find a code example to resolve this. I am not looking to do anything fancy. I don't want to display the footnote by hovering the mouse over the call to the footnote. I just want to be able to click on a footnote number and get to it at the bottom of the page and then return! I don't see how that is done without "NAME."
Currently as an example, this is what a my code looks like. (I make have ten or more footnotes on any given page.
<P>This is in the regular text
<A NAME="sdfootnote1anc" HREF="#sdfootnote1sym"><SUP>1</SUP></A>></P>
AND it calls this at the bottom of the page.
<p><DIV ID="sdfootnote1">
<A NAME="sdfootnote1sym" HREF="#sdfootnote1anc">1</A> - Here I am explaining it before I go on after the break to the next footnote.</DIV><BR>
Change name to id
<A CLASS="sdfootnoteanc" id="sdfootnote1anc" HREF="#sdfootnote1sym">
<A CLASS="sdfootnotesym" id="sdfootnote1sym" HREF="#sdfootnote1anc">1</A>
I'm no programmer, so this might be really messy. Maybe there's a cleaner method to create a mouseover pop-up?
I'm using an empty href to create a mouse over pop-up. My issue is that the empty href is not displaying as a link, so there is no indication that one should mouseover.
(<span title="Infrastructure, comprising a society's ... , and science (symbolic and ideational relations)."><i>'Infrastructural, Structural and Superstructural'</i></span>
I also tried: javascript:void(0); javascript:; and # (all to no avail); I finally settled for italics- but that is no real cue.
If you just want the pop-over title, you can put that on any element without having to use an empty (and non-semantic) a link.
Plus, considering your a tag is empty nothing will be rendered, so no link will be seen.
If I understand what you're trying to do correctly, I think your tags should be around the text.
<span title="Infrastructure, comprising a society's ... , and science (symbolic and ideational relations)."><i>'Infrastructural, Structural and Superstructural'</i></span>
You are close - but you need to know that <a href='...'> opens the tag and </a> closes it. The text between those two is the bit that show up underlined.
Blah
or...
<span style="color:blue" title="The definition of the term">the term used</span>
I am no coder, but know enough HTML to get the job done.
I have simple anchors for in-page linking and they work in every browser but Chrome.
What is the average joe explanation of what I can do to get them to work?
[a title="Important Safety Information" href="#isi"] Important Safety Information [/a]
[a id="ISI" name="ISI"][/a]
Page with anchor link: http://educationexchangehcp.ndei.org/novo/bolus-insulin-type-2-diabetes-education-novo-nordisk.aspx
Click on Important Safety Information on the right.
Please help! Thank you,
Brian
Your anchor is in all caps, but the link is in all lowercase. Change the <a id="ISI" name="ISI"></a> to <a id="ISI" name="isi"></a>. Also, if you're not using the ID tag for anything else, I'd just get rid of it. You don't need it for the anchor link to work.
HTML classes and ID names are case-sensitive. Change your code to [a title="Important Safety Information" href="#ISI"].
I'm trying to create a page where a user clicks on a link on the left and is taking to a specific section on the page.
Here is example. I've added as much of the code I'm using as I can.
What your trying to do works with the Id or Name attribute.
To elaborate: The anchor tag that your rendering as the target of where your page needs to go should be:
<a id="myId"></a>
or
<a name="myId"></a>
or both..
When you build a link to another part of the page, you need two parts, the link (that you click), and the target (that the page scrolls to).
The link's href attribute needs to start with a '#'. This signifies that the link is 'internal' to the page, and not another, external page.
The target can be either a named anchor <a name="something"></a> or an element with an ID: <div id="something">. You don't include the '#' in the name or the ID.
That's the key part you're missing. Take the '#' off the front of your <a name=""> values and it will work.
Let us know if that works, and we can help you develop this further: There's a lot more polish you could add, but let's get the basics working first.
I am trying to search/select a link in a page that is underlined, while others are not. The source is something like this:
<a href="someurl1">
<b>
<u>Some ulined text</u>
</b>
<u></u>
</a>
<br>
Other link text
<br>
Another Link text
<br>
I tried something like
link = browser.link(:u?, true)
link.exists?
I get the following errors
TypeError: expected one of [String, Regexp], got true:TrueClass
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:152:in `check_type'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:189:in `normalized_selector'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:188:in `each'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:188:in `normalized_selector'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:76:in `find_first_by_multiple'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:33:in `locate'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/elements/element.rb:260:in `locate'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/elements/element.rb:247:in `assert_exists'
from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/elements/element.rb:31:in `exist?'
Edit:
So I am actually using this for screen scraping rather than testing. That may explain the reasons why watir does not support this directly since CSS and other better practices make sense for testing and when you the HTML development and testing go hand in hand. Hoserver from a scraping perspective, the text formatting is what the user sees, and searching underlined, bold links etc. make sense for scraping.
I've never seen that kind of attribute used in a test case before. I also haven't seen any code support for it. You may have to roll your own. Here is an example borrowed from Zeljko
def hasUnderlined(browser)
s = false
browser.links.each do |l|
if l.html.downcase.match /\<u\>*\<\/u\>/
s = true
end
end
end
def getUnderlined(browser)
browser.links.each do |l|
if l.html.downcase.match /\<u\>*\<\/u\>/
return l
end
end
end
I don't think what you want is possible directly because the underline is not an attribute of the link tag, but a formatting tag that apples to just the text in the link.
However, in modern web pages, formatting is often controlled by a combination of CSS and attributes such as class names, which ARE something you could specify when identifying a link. So IMHO your best bet here might be to talk a little with your developers about how they are coding the site and see if they are perhaps open to increasing the testability of their code by using slightly more modern techniques for controlling what links are underlined, such as say using CSS and basing the underlining on a class name. (There's a lot of other good reasons to use CSS for controlling formatting instead of embedding it directly in the HTML, but unless your guys are fresh off the html-banana-boat so to speak, they should not need to be taught why using CSS is a good thing)
That would let you search for a link according to the class attribute that was being used to cause CSS to underline the text
If your developers are not open to such an approach to make their code more testable, then I think your only option is going to be to create your own ruby code for this and modify your copy of water (see #Dave's answer), and then be prepared to maintain that custom patch any time you update watir etc.
So, the only thing you know about a link is that it is underlined?
I thought this would do it (using the latest watir-webdriver gem):
browser.link.u.click
But I got this:
NoMethodError: undefined method `u' for #<Watir::Anchor:0x00000100cbb3c0>
Jari (watir-webdriver developer) said he thinks u tag is not in HTML spec.
By the way, this works:
browser.link.b.click
Jari suggested trying xpath, but I thought css selectors would be nicer to read. Here it is:
browser.element(:css => "a b u").click