2012-06-27 59 views
-1

我正在使用硒進行閃存測試。我想獲得嵌入標籤的id。 我用firepath得到xapth,它看起來像​​XPath Selenium xpath無效[2]

,當我試圖檢索它像

browser.getAttribute(("xpath=//[html/body/div[1]/div[6]/div/embed]")); 

然後我得到com.thoughtworks.selenium.SeleniumException: ERROR: Invalid xpath [2]: //*[html/body/div[2]/div[6]/object/embedd

我使用硒2 RC。請有人幫助獲取嵌入標記內的id屬性。

+1

很好的鏈接,使用的XPath:http://test-able.blogspot.ie/2016/04/xpath-selectors-cheat-sheet.html – 2017-05-30 14:33:29

回答

4

它在我看來像你正在使用getAttribute不正確。 Selenium的getAttribute方法採用attributeLocator作爲其參數。按照文檔描述,屬性定位器是一個元素定位器(在本例中爲xpath),後跟「@」和屬性名稱(在本例中爲id)。

嘗試

String xpath = "xpath=//[html/body/div[1]/div[6]/div/embed]"; 
browser.getAttribute(xpath+"@id"); 

同時仔細檢查你的代碼。你在你的代碼中說你寫了div[1],但是錯誤說div[2] - 你可能只是犯了一個錯字。這將解釋xpath錯誤,但您仍然需要更正您對getAttribute的使用。

Selenium getAttribute docs.