2013-11-21 63 views
0

我使用Xpathchecker FF插件來獲得XPath表達式,但是當我運行這段代碼:無效的選擇異常

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()); 


} 

我收到以下錯誤:

給出的選擇id('search_results_table')/ x:tbody/x:tr無效或不會導致WebElement。發生以下錯誤: InvalidSelectorError:由於以下錯誤,無法找到xpath表達式id('search_results_table')/ x:tbody/x:tr的元素: [Exception ...「嘗試創建或改變一個對象的方式是不正確的關於命名空間的代碼「code:」14「nsresult:」0x8053000e(NamespaceError)「location:」file:/// C:/ Users/orsyp/AppData/Local/Temp/anonymous8101865731711582627webdriver -profile/extensions/[email protected]/components/driver_component.js Line:5916「] 命令持續時間或超時時間:109毫秒 有關此錯誤的文檔,請訪問:http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info:version:'2.35.0 ',修訂:'c916b9d',時間:'2013-08-12 15:42:01' 系統信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1' ,java.ver錫安: '1.7.0_40' 會話ID:9cbc470a-c211-46ce-8bb1-ccdb9c66ff1e

這裏是我的html代碼,你可以看到這是一個動態表:

<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> 

+0

請提供html代碼,這樣我就可以用xpath來幫助你。你的xpath無效。 – Ievgen

+0

謝謝,HTML代碼已添加 – Ziwdigforbugs

+0

爲什麼你對此有幾個問題?之前向您解釋過,這在任何意義上都不是有效的XPath。您還向我們提供舊的日誌文件:''2013-08-12 15:42:01' – Arran

回答

1

假設你想要tbody中的所有行,xpath應該是:

//table[@id='search_results_table']/tbody/tr