0

I am using the Xpathchecker Firefox plugin to get the XPath expression, but when I run this code:

private void srch() throws MalformedURLException, IOException
{
  driver.get(TestURL);

  WebElement input1 = driver.findElement(By.id("login_form_user_input"));
  input1.sendKeys("guest");

  WebElement input2 = driver.findElement(By.id("login_form_password_input"));
  input2.sendKeys("guest");

  WebElement btn = driver.findElement(By.id("login_form_signin_button"));
  btn.click();

  WebElement w1 = driver.findElement(By.id("header_search_text_field"));
  w1.sendKeys("tsk");

  //WebElement resulttable = driver.findElement(By.id("search_results_table"));
  //System.out.println(resulttable.getSize());
  List <WebElement> rows = driver.findElements(By.xpath("id('search_results_table')/x:tbody/x:tr"));
  System.out.println(rows.size());
}

I get the following error:

The given selector id('search_results_table')/x:tbody/x:tr is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression id('search_results_table')/x:tbody/x:tr because of the following error:
[Exception... "An attempt was made to create or change an object in a way which is incorrect with regard to namespaces"  code: "14" nsresult: "0x8053000e (NamespaceError)"  location: "file:///C:/Users/orsyp/AppData/Local/Temp/anonymous8101865731711582627webdriver-profile/extensions/[email protected]/components/driver_component.js Line: 5916"]
Command duration or timeout: 109 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_40'
Session ID: 9cbc470a-c211-46ce-8bb1-ccdb9c66ff1e

And here is my HTML code. As you can see, this is a dynamic table:

<table id="search_results_table" class="table table-striped table-hover table-condensed  table-bordered">
    <tbody>
        <tr class="ng-scope" ng-repeat="object in objects">
            <td>
               <a href="#/en/object?company=WAR001&area=X&mu=BIST_CE691&name=TSK(BEN701JU50)(000)">
              <p style="font-size:11px">
            </td>
        </tr>
        <tr class="ng-scope" ng-repeat="object in objects">
        <tr class="ng-scope" ng-repeat="object in objects">
        <tr class="ng-scope" ng-repeat="object in objects">
        <tr class="ng-scope" ng-repeat="object in objects">
        <tr class="ng-scope" ng-repeat="object in objects">
        <tr class="ng-scope" ng-repeat="object in objects">
        <tr class="ng-scope" ng-repeat="object in objects">
    </tbody>
</table>
4
  • Please provide html code, so I'll be able to help you with xpath. Your xpath is not valid. Commented Nov 21, 2013 at 13:56
  • Thanks, HTML code added Commented Nov 21, 2013 at 13:58
  • Why have you made several questions about this? It was explained to you before, that isn't a valid XPath in any sense. You are also providing old log files to us: '2013-08-12 15:42:01 Commented Nov 21, 2013 at 14:46
  • Sorry I got confused. Commented Nov 21, 2013 at 15:13

1 Answer 1

2

Assuming you want all rows in the tbody, the XPath expression should be:

//table[@id='search_results_table']/tbody/tr
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.