I am writing Selenium script. For a html page include a table, I can not use "css=table tr:nth-child(2) td:nth-child(3) a" to locate the link in the table. Selenium IDE give me the "[error] locator not found".
But use "css=table tr:nth-child(2)", it can locate to the row.
So am I mistake for the css locator, I think adding the "td:nth-child(3) a" should work for the link in td , why not?
Edit: I am using firefox 3.0.15
Given the HTML:
<html>
<body>
<table>
<tr><td>Hello</td><td>World</td></tr>
<tr><td>I'm</td><td>Batman</td></tr>
</table>
</body>
</html>
You can use the following locator for the link in the 2nd column of the 2nd row:
css=tr:nth-child(2) > td:nth-child(2) > a
Update:
After a little bit of research, it seems your original locator should work, but doesn't due to a bug in the cssQuery library used by Selenium (http://jira.openqa.org/browse/SEL-698). My suggestion above works, but it's really only a workaround until the bug is fixed. Unfortunately, considering the cssQuery hasn't been updated for some time I'm not sure how soon this will be addressed.
A similar issue is still around in Selenium IDE 2.1.0
I'm testing a group of web sites to check if a specific URL has been changed.
The link I'm supposed to check for is in a table, in the 25th or so tr from the top ...
<tr>
<td>
<div align="center">
<font color="#FFFFFF">
<a target="_blank" href="http://[The link I need to test] ...
I've used both
assertElementPresent //*[starts-with(#href,'The Link')]
and
assertElementPresent //*[contains(#*,'The Link')]
In some cases, the first one will find a result, but the second one will not. Most of the time neither will find the Link.
Related
In the last days we have seen how our newsletters doesn't print as they use to do in Yahoo Mail. Some <td> elements are taking more space that they were supposed to take. After some checking we have seen that width attributes in our inline styles are replaced by min-width.
I was try to see if there were any change in Yahoo Mail but I couldn't find anything. The only thing I have found an issue in github explaining how this behaviour is suppose to happen in Yahoo and in Gmail with the height. I've checked Gmail and it's not happening and everything was ok last week in Yahoo Mail.
Is anyone suffering the same issue? Does anyone know the explanation to that?
This is one of the newsletters suffering the problem, and this is how we see it now.
I answered this question earlier today, here's that answer:
Quick fix, place this in your <style> tag: #media yahoo {min-width:0!important}
This change/bug is brand new at the time of this posting. Yahoo is now changing width to min-width, breaking hybrid layouts among other things. There is a good discussion about other hacks in the Litmus Community.
Table elements for my purpose are parent elements to a button.
For (parent) table elements I placed "!important" next to "min-width" with no spaces.
The html is placed "inline". See the example below:
<table align="center" width="200px" bgcolor="#0076be" style="border-spacing:0;Margin:0 auto;width:95%;max-width:200px; min-width:0%!important;">
Button element has no inline style element of "width".
See example below:
<img src="[[asset_3]]" width="195px" style="border-width:0;max-width: 195px; height:auto;display:block;margin:0 auto;" border="0" alt="Click Show Images to Make Links Work">
Visit Yahoo Mail Update Potentially Breaks Hybrid Emails for more information.
I am trying to print the href of a html doc, however I am not able to do so.
newurl = 'http://www.heroesfire.com/hots/guide/the-many-ways-of-abathur-1194'
buildpage = Nokogiri::HTML(open(newurl))
#puts buildpage
thistext = buildpage.css("div#wrap div#site-content.self-clear div#guide.view-guide div.col-l div.tab-contents.box div.guide-tab div.chapter-text div.text table.bbcode_columns tbody tr td.bbcode_column a").each do |href|
puts href['href']
end
I am expecting to see '/hots/wiki/talents/pressurized-glands'
I was able to get something similar to work earlier in my script, but I am having zero luck with this.
Invariably, the longer the Node selector, the less likely it will work correctly, especially if you're dealing with HTML you don't control.
Reduce it to find way-points, places that help you drill down instead of trying to define each step.
You're also relying on tbody in the selector. When we see that, the odds are good that it's not in the original HTML source but instead was injected by your browser. Selectors like that smell of using a browser and an inspector to locate a particular item in the page, but the resulting path won't work if the HTML doesn't actually contain tbody. Browsers do a lot of fix-up in an attempt to present something useful, including adding tags. So be careful when you see tbody and confirm it actually exists. In your case, it does, but the concern still exists when navigating through a document.
A simple example of simplifying the path is:
require 'nokogiri'
doc = Nokogiri::HTML(<<EOT)
<html>
<body>
<div id="foo">
<div id="bar">
<p>text1</p>
</div>
<div id="baz">
<p>text2</p>
</div>
</div>
</body>
</html>
EOT
doc.at('body div#foo div#bar p').text # => "text1"
Can be written more easily, while still accomplishing the same thing, using:
doc.at('#bar p').text # => "text1"
or perhaps one of these:
doc.at('#foo div p').text # => "text1"
doc.search('#foo div p').first.text # => "text1"
All scraping requires at least some advance knowledge of the target page's structure, so, while you're nosing around, take note of the important layout tags. id parameters are especially useful, followed by class and/or unique patterns of tags not replicated elsewhere in the document. Those make it easy to reduce the selector. Sometimes we have to step into the document incrementally like I did using first or one of the "sibling" methods after locating a particular node, but using a long selector rarely is needed.
In the following example, the word Test is not clickable in Internet Explorer, even though the link URL appears at the bottom of the page when it's hovered over, and the link's area is represented accurately in the horrible IE debugging tool (F12). This works fine in all other browsers (of course).
<table><tr><td>Test</td></tr></table>
I know it's not technically valid to nest a table inside a hyperlink tag, but it's really the only practical way to do what I want to accomplish, and seeing how it works fine in all browsers, is there a way to get it to work in IE?
So far, I've tried giving both the table and link a height, width, and also a display property of inline-block. None have worked. Thanks.
You say "seeing how it works fine in all browsers" -- but that's really not true. What's actually happening in some browsers is they're doing work to make it work.
Do something like this instead:
<table onclick="location.href='/'" style="cursor: hand;">
<tr><td>Test</td></tr>
</table>
Also a hack, but a more valid one.
UPDATE
If you have concens about crawlers, there are two possible approaches. One is to add a link after, something like:
<table onclick="location.href='/'" style="cursor: hand;">
<tr><td>Test</td></tr>
</table>
Test
You can also use a <link> tag in the <head> of the document, something like:
<link href="/" rel="section" />
Or whatever link rel type makes sense.
Additionally, HTML structured as you have in your question is invalid according to the spec. In terms of what works reliably and into the future, your code does not qualify. Code written more towards an eye on standards will work more reliably.
ANOTHER UPDATE
Given your comment, here's how I would structure this, assuming markup like this:
<table class="dataTable">
<tr>
<td><img></td>
<td>Description</td>
<td>Details</td>
</tr>
</table>
Your details link represents the link you're using, so what I would do is add this bit of JavaScript (uses jQuery, but could be rewritten for whatever libraries you're currently using:
<script>
jQuery(function($){
$('table.dataTable').delegate('td', 'click', function(){
$(this).find('a.details').trigger('click');
});
});
</script>
I have a client form which includes HTML served up from an iframe - I can't edit it. The only thing I can do is apply CSS edits.
I'm trying to apply a simple adjustment which would stack the <td>s in the form so
1. What is your age?
becomes
1.
What is your age?
If you right click the first question and Inspect Element you'll see the rather interesting DOM structure I get to work with. This example it looks like this:
<div id="Age" class="questionlabel">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<span class="questionnumber_questionlabel">1. </span>
</td>
<td>
<label class="required">What is your age?</label>
</td>
</tr>
</tbody>
</table>
</div>
When I inspect that <td> and add a display:table-row; it completely ignores me. This is in Chrome - I can replicate this DOM and get the CSS to do what I want in jsfiddle so I'm thinking there is a reset somewhere I can't see. I even tried display:table-row !important; to no avail. I can apply border:2px solid blue; no problem. I can apply display:none; no problem.
Any ideas as to what is going on here that would prevent this simple CSS param from working?
To re-iterate the ONLY thing I can do is apply CSS - No JavaScript and no HTML edits. Basically I pass in a CSS file in the url to the iFrame. That's all I get. Thanks!
EDIT: I apologize I had to remove the link to the example form on the live site.
Edit - screenshots had to be removed, but the solution is still valid.
Added this code to form-css.css, using Firebug. Beginning or end, it did not matter:
table#form_table div.questionlabel td {display: table-row !important;}
.questionnumber_questionlabel {margin: inherit!important;}
(Note: I reset that margin as the old one (-10px) was causing unsightly overlap.)
I have one error when validating my Joomla built site against the W3C validator. It's a closed tag but without an opening tag. Problem I'm having is the tag appears to be completely unrelated to any other elements and I can't see it via Firebug. Anyone know how I can track down what's causing this? It's a right pain. Details from the validator:
Line 403, Column 5: end tag for element "h2" which is not open
The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.
If this error occurred in a script section of your document, you should probably read this FAQ entry.
and a snippet of how it appears in the HTML from view source:
<div id="ja-current-content" class="column" style="width:100%">
<div class="ja-content-main clearfix">
</h2>
<div class="article-content">
<h1>Welcome to SWAYsearch web design, Cambridge</h1>
The site is: http://www.swaysearch.com
Any help much appreciated.
Cheers
John
That's a known bug when you have title's disabled. You'll have to open that file manually and comment out that if statement which leaves the stray closing h2 tag.
I believe the opening h2 tag is this:
<h2 class="contentheading clearfix">
Search through your code for that string and you should find your issue.