Attribute ddata-horizontalposition not allowed on element li at this point- w3c validator - html-lists

w3c validator shows this error:
Attribute ddata-horizontalposition not allowed on element li at this point.
<li data-text-id="#bannerscollection_kenburns_photoText4" ddata-horizontalPosition="center" data-verticalPosition="center" data-initialZoom="1" data-finalZoom="1"></li>
Someone please help me

Just try this:
<li data-text-id="#bannerscollection_kenburns_photoText4" data-horizontalPosition="center" data-verticalPosition="center" data-initialZoom="1" data-finalZoom="1"></li>

The attribute ddata-horizontalPosition is not allowed in HTML5.
It probably should be
data-horizontalPosition="center"
See http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes.

Related

Obtain an xpath element containing another element with an specific class

Hello I have this HTML:
<div class="_3Vhpd"><span>Your commerce Data</span>
<a class="n3G0C" href='http://www.webadress.......'><span>Some Text</span</a>
</div>
I tried to obtain the tag as follow:
parser.xpath('//div[contains(#class,"_3Vhpd")]//following-sibling::*[a[#class="n3G0C"]]/#href ')
but I received none '[]'. Maybe because is not just after div but after a span...
First, you sample html doesn't have a class="n3G0C", but assuming you fix it, this xpath expression should work:
//div[contains(#class,"_3Vhpd")]//following-sibling::a/#href
Output:
http://www.webadress.......

What is Valid Xpath for link extract by div class name?

What is Valid Xpath for link extract by div class name?
Here is html code:
<div class="poster">
<a href="/title/tt2091935/mediaviewer/rm4278707200?ref_=tt_ov_i"> <img alt="Mr. Right Poster" title="Mr. Right Poster" src="http://ia.media-imdb.com/images/M/MV5BOTcxNjUyOTMwOV5BMl5BanBnXkFtZTgwMzUxMDk4NzE#._V1_UX182_CR0,0,182,268_AL_.jpg" itemprop="image">
</a> </div>
I want to know exact Xpath as if i found href link.
I try with //a/#href[#class='poster'] but it's doesn't work
The <div> contains the <a> so you can use that to navigate:
//div[#class='poster']/a/#href
Remember that the "poster" class is defined on the <div> not on the <a> so that's where you need to apply the predicate.
//div returns all <div> elements
[#class='poster'] is a predicate that filters by class
/a returns all <a> elements that are children of those <div>s
/#href gives us the attribute we want
Depending on the system you're using you might need to wrap the whole expression in text() in order to bring back the attribute data rather than the DOM node.

Capybara::ElementNotFound Exception when the element is constructed dynamically

In cases when we have a dynamic content population in a span tag,
for e.g.,
.detail
%label Sku:
%span.#sku.detail= #deal.sku
When the deal in the above example doesn't have sku associated, the span element in the html will be as below
without any content in it.
<div class="detail">
<label>Sku:</label>
<span id="sku" class="detail"></span>
</div>
If the SitePrism element is defined to look for this for e.g.,
element :sku, "#sku"
and if "#sample_page" is reference to my Site Prism page, and I refer sku as
#sample_page.sku.text
we will get Capybara::ElementNotFound Exception
To avoid this we can check as below
#sample_page.has_sku?
and if the element is available then proceed with the actions as required.
This will omit Capybara::ElementNotFound Exception
When the span has no content it is not visible and thus not found. If you still want to find it, change your element to something like:
element :sku, "#sku", visible: false

Select element by attribute value with XPath in Nokogiri

So if I have this piece of code
<body>
<div class="red">
<a href="http://www.example.com>Example</a>
</div>
</body>
I know that I want to get an element with the attribute "class" and value "red" but I don't know where is located.
If I used XPath, is this piece of code right?
dir = "http://www.domain.com"
doc = Nokogiri::HTML(open(url))
doc.xpath('.//*[class="red"]')
I'm just learning so I don't know if any of this is wrong. I can't make it work. Thanks.
Edit: Now it's working =)
doc.xpath('//*[#class="red"]')
Change class to #class. Remove the dot in the beginning. Then it will work.

How to check of a Node is inside a form tag?

Using XPath, how do I determine if a node is within a form tag? I guess I am trying to locate the form tag of its ancestor/preceding (but I couldn't get it to work).
example 1:
<form id="doNotKnowIDofForm">
<div id="level1">
<span id="mySpan">someText</span>
</div>
</form>
example 2:
<form id="doNotKnowIDofForm">
This is a closed form.
</form>
<div id="level1">
<span id="mySpan">someText</span>
</div>
</form>
I can use xpath "//span[id='mySpan']" to locate the span node. But I would like to know if mySpan is inside a form (I do not know the id of the form). I have tried "//span[id='mySpan']/preceding::form/" and "//span[id='mySpan']/ancestor::form/"
Thanks in advance.
EDIT: I would like the XPath to select the myForm form tag in Example1 but NOT in Example2
I'm not 100% sure from your description whether you're looking to select the form element, or the span element. It seems more likely that you're going for the form, so I'll address that first.
Your XPath with the ancestor::form would have been ok if it didn't have the slash at the end, but it's more roundabout than it needs to be. I think this is a better way:
//form[.//span/#id = 'mySpan']
or this:
//form[descendant::span/#id = 'mySpan']
To produce an XPath that locates certain nodes only if they are within a form, you would put the ancestor::form inside the predicate:
//span[#id = 'mySpan' and ancestor::form]
or you can do this, which would again be more straightforward:
//form//span[#id = 'mySpan']
Your own attempt
//span[id='mySpan']/ancestor::form/
looks fine to me.
You can simply use,
"form//span[id='mySpan']"

Resources