2016-11-22 53 views
0

鉻我得到的XPath值: //*[@id='user_change_pw_form']/div[3]/span爲什麼在XPath定位於Chrome和Firefox/Firebug的在Selenium測試不同

,並在螢火蟲相同的元素,我得到: /html/body/div[2]/form/div[3]/span

爲什麼我不得不speparate的XPath查詢一樣,得到一個和硒測試用例相同的元素:

switch (System.getProperty("test.driver")) 
     { 
      case "chrome": 
      case "html": 
       text = driver.findElement(By.xpath("//*[@id='user_change_pw_form']/div[3]/span")).getText(); 


      case "gecko": 
       text = driver.findElement(By.xpath("/html/body/div[2]/form/div[3]/span")).getText(); 
       break; 

     } 

雖然各自對應給出了錯誤的瀏覽器「無法LOCA te元素「,儘管兩個xpath查詢都可以在兩個瀏覽器控制檯中使用。

在此先感謝!

+0

檢查:http://stackoverflow.com/questions/23053632/is-xpath-is-different-for-different-browser – noor

+0

明白了!謝謝! – Leder

回答

0

firefox具有絕對xpath並且無法處理chrome的xpath。

感謝@noor和@Kenil發嗲

0

嘗試編寫自己的xPath/CSS選擇器,而不是依賴基於瀏覽器的選擇器。這link會幫助你學習/編寫你自己的選擇器。

我也建議在xpaths上使用css選擇器,因爲它們更具可讀性。

相關問題