Not sure if this fits your problem, but one approach would be to look at the 
output of b.div(:id, 'contents').text. It may be possible to use regexp 
matching to get the text leading up to the div and then the text after, without 
having to worry specifically about what element outside the table the text is 
stored in. For example, maybe the table has a static header row and you know 
that the first 2 column row names are going to be foo and bar. You could then 
write a regexp to get the text above the table. And then use a similar strategy 
to get the text below. Then you don't have to worry about dynamic table updates 
in between checks for the text values of elements within the div. If you see 
some reliable pattern marking the beginning and end of the table text then this 
should work. 
Alternative idea is to get the enclosing div HTML, use a regexp to strip out 
the table tags and everything between and then feed the resulting string to 
Nokogiri for further manipulation (either convert remainder to text or traverse 
the remaining elements one by one.) Seems sort of low rent but that would 
definitely work.
      From: Derek W <[email protected]>
 To: watir-general <[email protected]> 
 Sent: Friday, December 4, 2015 1:31 PM
 Subject: Re: [wtr-general] How can I get all the content in a div element then 
strip out a table element leaving only what elements I want?
   
What is the context?  Are you first getting the div via xpath and storing it in 
a variable?
If so, you can just do a regex using something like this right? 
"<table>[0-9a-zA-Z<> \/]*<\/table>"
If you're trying to do this all in 1 xpath locator, can't you do something like:
//div[@id="contents"]//table//text()




On Fri, Dec 4, 2015 at 1:17 PM, Super Kevy <[email protected]> 
wrote:

How can I get all the content in a div element then strip out a table element 
leaving only what elements I want?

Assume  a structure like
<div id="contents><p>Static text I want to offline into a file as a static 
comparison later</p><p>If the static content is updated by a change request I 
will detect the changes by a file compare</p><table><tr><td>this table is 
dynamic is updated with new values all the time</td></tr><t/able><p>More static 
content</p><ul><li>etc, etc</li></ul></div>

 The notion is I store the statics in a file then iterating a test that can 
compare the current static elements to an offline file and let me know if there 
are changes. I would like to be able to strip the table from the div wrapper 
and just see the whats left for the comparison.

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.
 
[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.




-- 
Derek Wrobel
425-243-3355-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.
 
[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.


 

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to