skip to Main Content

I’ve a bit of challenge that I cannot figure out.

I’ve an HTML doc where a nested iframe host another set of meta tags. I’d like to reach them out via an XPath query, but when testing something like //iframe[.//meta[@name='robots']] there is no match.
I’ve tried multiple combination by now, without success.

My understanding is that iframe content is normally flattened within the rendered view, hence it should be fully traversable.
In fact a simple .//meta[@name='robots'] works fine.

enter image description here

Reason for asking is to intercept all meta tags in a webpage, while excluding those included in the iFrame.

2

Answers


  1. Chosen as BEST ANSWER

    I'm not sure and clear why this works the other way round than it should be, but eventually the following XPATH does the trick.

    //meta[@name='robots'][(/descendant-or-self::iframe)]
    

    Using the page given as the example in the previous comment, editing the rendered HTML to add a testing meta robots in the upper and using the above XPATH returns only that single instance.


  2. It seams like iframe as element is not recognized by Xpath.

    Instead you could try for all meta not in iframe:

    //meta[not(ancestor::body)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search