如何使用Selenium WebDriver提取<nobr>内部的动态文本?

时间:2019-01-25 08:03:58

标签: javascript java selenium-webdriver

我正在尝试在<nobr>标记内以DOM中的文本格式获取服务器文件名,但出现调用程序错误。

错误

Invokemethod error(source not found)
Need the text to be stored in string using selenium webdriver- "/services/aps/load_files/upload/WireTransfer_BatchImport_CForeignUSD_155342006955_201901250134.csv"

HTML代码

<table id="innerTable" class="summaryTable" cellspacing="0" 
  cellpadding="0" style="">
  <tbody>
    <tr
       onclick="updateOID('155341609897','E_IMPORT_FILE_UPLOADED');
       onRowClick();" 
       rowvalues="155341609897E_IMPORT_FILE_UPLOADED" 
       class="summaryRow_Even">
      <td class="summaryCell" nowrap="" style="width: 275px;">
        <nobr 
           style="width:275px;">
             WireTransfer_BatchImport_CForeignUSD.csv&nbsp; 
        </nobr>
      </td>
      <td class="summaryCell" nowrap="" style="width: 631px;">
         <nobr 
            style="width:631px;">
            /services/aps/load_files/upload/WireTransfer_BatchIm 
            port_CForeignUSD_155342006955_201901250134.csv&nbsp; 
         </nobr>
      </td>

到目前为止我尝试过的东西

String text = getDriver().findElement(By.xpath("//*[@id='innerTable']/tbody/tr[1]/td[2]/nobr/text()")).getText();
String text = getDriver().findElement(By.xpath("//*[@id='innerTable']/tbody/tr[1]/td[2]/nobr/text()")).getAttribute("innerHTML");

也尝试过

String text = getDriver().findElement(By.xpath("//nobr[contains(text(),'/services/aps/load_files/upload/WireTransfer_BatchImport_CForeignUSD')]")).getAttribute("innerHTML");

1 个答案:

答案 0 :(得分:0)

希望这可以// // nobr [contains(text(),'/ aps')]

enter image description here