How to check response from XML file using Selenium IDE

1,296 views
Skip to first unread message

unni

unread,
Aug 8, 2012, 3:30:13 AM8/8/12
to seleniu...@googlegroups.com
access a url and i get group response as below. I want to store these count for each specific id and compare the results with other response where i get individual response as mention in below.
HOW CAN I ACHIEVE THIS?
Group Response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <response> <results> <result> <id>Xref</id> <count>1</count> <landingpage>http://xxx.yy.org/1367</landingpage> </result>
 
<result> <id>Yref</id> <count>2</count> <landingpage>http://xxx.yy.org/1367</landingpage> </result>
 
</results>
</response>



Individual response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <response>
 
<result> <id>Xref</id> <count>1</count> <landingpage>http://xxx.yy.org/1367</landingpage> </result>
</response>


Regards,
Unni

unni

unread,
Aug 8, 2012, 3:35:43 AM8/8/12
to seleniu...@googlegroups.com
just edited as the entire content is not visible

Mark Collin

unread,
Aug 8, 2012, 5:34:58 AM8/8/12
to seleniu...@googlegroups.com

If you are loading the xml up in a browser you should be able to run xpath queries against it.

 

driver.findElements(By.xpath(“//id”)).size();

 

The above is of course assuming you use Java (for other languages replace size with whatever command gives you the size of a list/array)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yoj-jBvl3KYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

unni

unread,
Aug 8, 2012, 6:03:45 AM8/8/12
to seleniu...@googlegroups.com
This is the total html i am getting when i inspect the page using FireBug. This page has count element for different id. I want to store these count for specific id using Selenium IDE. Then again i will access the url for specific id and compare the count for that specific id.. like wise i want to match the count for all ids.

<html><head></head><body><pre>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;response&gt;
    &lt;results&gt;
        &lt;result&gt;
            &lt;id&gt;XXref&lt;/id&gt;
            &lt;count&gt;1&lt;/count&gt;
            &lt;landingpage&gt;http://xxx.yy.org/1367-2630&lt;/landingpage&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;citeXX&lt;/id&gt;
            &lt;count&gt;0&lt;/count&gt;
            &lt;landingpage&gt;http://www.ZZZ.org/doi/10.1088/1367-2630&lt;/landingpage&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;XXtea&lt;/id&gt;
            &lt;count&gt;4&lt;/count&gt;
            &lt;landingpage&gt;http://www.SS.org/uri/a7568eb024f737044379d7ba34f1d224&lt;/landingpage&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;XXblog&lt;/id&gt;
            &lt;count&gt;0&lt;/count&gt;
            &lt;landingpage&gt;&lt;/landingpage&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;XXdeley&lt;/id&gt;
            &lt;count&gt;0&lt;/count&gt;
            &lt;landingpage&gt;&lt;/landingpage&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;XXtcove&lt;/id&gt;
            &lt;error&gt;
                &lt;type&gt;SERVICE_NOT_AVAILABLE&lt;/type&gt;
                &lt;message&gt;Unable to connect to remote connector service&lt;/message&gt;
            &lt;/error&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;XXcentral&lt;/id&gt;
            &lt;error&gt;
                &lt;type&gt;INVALID_RESPONSE&lt;/type&gt;
                &lt;message&gt;Remote connector service returned invalid response&lt;/message&gt;
            &lt;/error&gt;
        &lt;/result&gt;
        &lt;result&gt;
            &lt;id&gt;XXscholar&lt;/id&gt;
            &lt;count&gt;1&lt;/count&gt;
            &lt;landingpage&gt;http://dd.com/scholar?hl=en&amp;amp;cites=http://dx.doi.org//10.1088/1367-2630&lt;/landingpage&gt;
        &lt;/result&gt;
    &lt;/results&gt;
&lt;/response&gt;
</pre></body></html>

Mark Collin

unread,
Aug 8, 2012, 6:30:48 AM8/8/12
to seleniu...@googlegroups.com

OK you aren’t getting XML back you are getting HTML with text that looks like XML

 

You could probably grab all the text inside the <pre> tag, convert all &lt; to < and then convert all &gt; to > and then try and programmatically create an XML document from it and then perform some XPath checks on that. 

 

It’s a bit long winded though.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ceWUWHWsJUcJ.

unni

unread,
Aug 8, 2012, 7:29:58 AM8/8/12
to seleniu...@googlegroups.com
 Here we have page looks like <html><body><pre> XML CONTENT </pre></body></html>
 Xpath to access the xml content is html/body/pre.. no other xpath available in this page. Then How do we get Xpath here to check the count for corresponding id as per your view  Mark?

Mark Collin

unread,
Aug 8, 2012, 7:59:49 AM8/8/12
to seleniu...@googlegroups.com

Go back and read my previous comment again.

 

You are not getting XML content.  You are getting text that looks like XML content all of the < and > have been transformed into html.

 

You need to get the text of the <pre> element and then transform all the &lt; and &gt; back into < and > and then you can programmatically create a new XML document from it using something like the Java XOM library (http://www.xom.nu/).  You can them programmatically perform an XPath query on this XML document to find out how many <id> elements there are, use the XPath //id.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/v5U-MGCDHLAJ.

Reply all
Reply to author
Forward
0 new messages