2013-02-20 82 views
1

如何提取「幫助文件」類後的數據。這裏這個文本幫助文件是一個鏈接,當它點擊它時,我會導致另一種形式。 你們任何人都可以請我建議我如何繼續下去。我是Selenium的新手,我在這裏受到重創。我嘗試通過提取xpath,但它給了我的主頁的路徑
我正在使用硒webdriver和Eclipse Eclipse。我的項目只支持IE。如何提取硒中的標記之間的數據


幫助文件
CODE FILE

+0

發佈您的HTML源代碼。 – Manigandan 2013-02-20 06:45:37

+0

對不起,這是我的HTML代碼
HELP FILE
CODE FILE
\t \t ------ \t \t – Divya 2013-02-20 07:21:35

+0

Divya請讓你的問題更清楚。你是否試圖從'href'標籤中獲取'HelpFile'文本?我對嗎? – Manigandan 2013-02-20 07:32:40

回答

1

試試這個代碼:

// Assume driver in initialized properly 
String strText = driver.findElement(By.id("Locator id")).getText(); 
// Print the text of the Web Element 
System.out.println(strText); 
0

這是一個答案,它將返回具有相同的字符串查詢標籤內的WebElement (幫助文件)。希望這會幫助你,不知道我是否理解了這個問題。

由於您想根據其中存在的文本操作WebElement,所以會觸發我,所以此方法很可能適用於您。

public WebElement getMessage(final WebDriver driver, final String query) { 
    List<WebElement> wlcmLinks = driver.findElements(By.className("wlcmlink")); 
    WebElement finalLink = null; 
    Iterator<WebElement> itr = wlcmLinks.iterator(); 

    while(itr.hasNext() && (finalLink == null)) { 
     WebElement link = itr.next(); 
     if (link.getText().equals(query)) { 
      finalLink = link; 
     } 
    } 

    if (finalLink == null) { 
     throw new NoSuchElementException("No <a /> with that String"); 
    } 

    return finalLink; 

} 
0

試試這個。它可能工作..

String helpFile = driver.findElement(By.xpath(「// td [1] // a [1] // * @ class ='wlcmlink']」))。getText() ; ();}}}。getText();}}}。

+0

更改td []數字,您的文本存在。 – user2087450 2013-02-25 12:16:41

相關問題