我followig HTML代碼,並且希望X路徑文本「分析&研究」我怎麼能寫我自己的XPath從HTML代碼
<div id="LLCompositePageContainer" class="column-wrapper">
<div id="compositePageTitleDiv">
<h1 class="page-header">Analytics & Research</h1>
</div>
我正在使用Chrome以下xpath
,但沒有工作。
//*[@id="compositePageTitleDiv"]
這是我的代碼
WebElement header = driver.findElement(By.xpath("//div[@id='LLCompositePageContainer']/div[@id='compositePageTitleDiv']/h1[@class='page-header']"));
String header2 = header.getText();
System.out.println(header2);
和下面的錯誤我得到
異常線程 「main」 org.openqa.selenium.NoSuchElementException: 無法找到與元素xpath == // div [@ id ='LLCompositePageContainer']/div [@ id ='compositePageTitleDiv']/h1 [@ class ='page-header'] (警告:服務器沒有提供任何堆棧跟蹤信息) 命令持續時間或超時:10.34秒有關此 錯誤文檔,請訪問: http://seleniumhq.org/exceptions/no_such_element.html
看看這個:http://stackoverflow.com/questions/24212548/how-to-get-the-absolute-xpath-for-an-element-within-firebug –
不幸的是我不能用戶Firefox或螢火蟲到期在IT策略,由於 – Amol1981
請界定「沒有工作」,提供您的相關代碼,您收到錯誤消息/行爲。 – OCary