get using xpath many answers

18 views
Skip to first unread message

yaqua

unread,
Jul 13, 2009, 7:49:15 AM7/13/09
to selenium-users...@googlegroups.com
Hi Experts

this xpath
//tr[contains(@id,'dbGridRow')]
can return me more than one answer

to select the second answer I need to use
//tr[contains(@id,'dbGridRow')][2]


for performance reasons. I want to invoke one command in the selenium that will return me all the results, and the analyzing of the result I'll will make in my code
for exmaple :
seleniumClient.getText("//tr[@id='dbGridRow2]");
will return me the first restul.
I want that selenium will return me all the results as an array
there is such option ?

Thanks

Sascha

unread,
Jul 13, 2009, 8:49:48 AM7/13/09
to selenium-users...@googlegroups.com
I am taking the innerHTML of a DOM node:

    /**\\      * returns the innerHTML for a DOM element identified by a XPath\\      * \\      * @param xPath XPath of the DOM element\\      * @return the inner HTML as String\\      */\\     public String getInnerHtml(String xPath) {\\         xPath = xPath.replaceAll("\"", "\\\"");\\         \\         return selenium.getEval("this.page().findElement(\"" + xPath + "\").innerHTML");\\     }

Then I am converting this to a Document object using HtmlCleaner (http://htmlcleaner.sourceforge.net/index.php). Then I can execute XPathes against this. I am using this offen to e. g. get all tab titles of a Dojo TabContainer.

yaqua

unread,
Jul 13, 2009, 9:43:43 AM7/13/09
to selenium-users...@googlegroups.com
You right
But I can't use this method from performance reasons.
Thanks

yaqua

unread,
Jul 13, 2009, 9:46:34 AM7/13/09
to selenium-users...@googlegroups.com
Hi

you write me to use
   return selenium.getEval("this.page().findElement(\"" + xPath + "\").innerHTML");


In my code it's
  seleniumClient.getEval("selenium.browserbot.getCurrentWindow().findElement(\"" + xpath + "\").innerHTML");

but I get this exeception
{font:style=font-family: Courier New; font-size: 10pt;}com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: Expected ')' \\         at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97) \\         at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91) \\         at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262) \\{font}\\
do you know why ?

Sascha

unread,
Jul 13, 2009, 1:53:23 PM7/13/09
to selenium-users...@googlegroups.com
The line

xPath = xPath.replaceAll("\"", "\\\"");

is quite important as it replaces any " character in the xPath with \" so that it prevents syntx errors in the JavaScript. I assume you are not doing this as expected ')' means that the string in getEval() is finished but no ) follows.

But you may also give me a look at the Selenium RC log. Maybe there is something else that I did not mention (and not run in on my system).

EDIT: thinking about this more ... I do not have any xPath containing ". The correct line could also be

xPath = xPath.replaceAll("\"", "\\\\\"");

but I am at home now and cannot check this.

Reply all
Reply to author
Forward
0 new messages