2012-06-27 65 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.