2017-04-06 71 views
-1

我想從下面的代碼中獲取文本。這裏我想複製.js_count課文結果。硒的css選擇器

<div class="search-result-bar"> 
    <div class="search-result-bar-country"> 
     <a class="search-result-bar-country-title" href="javascript:void(0);" title="paris">paris </a> 
     <span class="search-result-bar-country-dot"> 
     · 
     </span> 
     <span class="search-result-bar-country-count"> 
      <span class="js_count">10146</span> 
      <span class="js_text"> rentals</span> 
     </span> 
    </div> 
</div> 

錯誤日誌:

*** Element info: {Using=css selector, value=span.js_count} at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ‌​e Method) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknow‌​n Source) at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Un‌​known Source) at 
java.lang.reflect.Constructor.newInstance(Unknown Source) at 
org.openqa.selenium.remote.http.W3CHttpResponseCodec.createE‌xception(W3CHttpResp‌​onseCodec.java:133) 
+0

嘗試xpath'「// span [@ class ='js_count']」' –

+1

歡迎來到Stack Overflow!請閱讀[問]。 – JeffC

回答

1

可以使用下面XPath表達

//span[@class="js_count"] 

CSS選擇

span.js_count 

來定位所需的元素,然後使用getText()方法提取其文本內容

+0

我試着用CSS選擇器,但總是得到這個錯誤 ***元素信息:{Using = css selector,value = span.js_count} \t在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本機方法) \t在sun.reflect.NativeConstructorAccessorImpl.newInstance(來源不明) \t在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(來源不明) \t在java.lang.reflect.Constructor中.newInstance(Unknown Source) \t at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:133) \t at – zsbappa

+0

使用'編輯'選項來更新您的票已經嘗試過的選擇器和錯誤日誌 – Andersson