javascript - 如何使用 selenium webdriver 提取 <nobr> 中的动态文本?

标签 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");

最佳答案

希望这能起作用//nobr[contains(text(),'/aps')]

enter image description here

关于javascript - 如何使用 selenium webdriver 提取 <nobr> 中的动态文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54361185/

相关文章:

javascript - 如何确保所有 JavaScript 错误都写入 Chrome 开发者工具控制台?

javascript - 如何使用 jQuery 重置 CSS?

javascript - 如何以编程方式区分箭头函数和常规函数?

java - @OneToMany 关系 hibernate

javascript - gulp 4中如何同时看sass和javascript

java - 重构用于测试的静态方法/静态字段

java - Spark +速度: Unable to load resources (ResourceNotFoundException)

java - 当在 webdriver 的页面中找不到 webElement 时,不会出现 NoSuchElementexception

javascript - 无法使用 JavaScript 关闭 chrome 浏览器中的选项卡

python - Selenium Python 等待文本出现在元素错误显示需要 3 个参数 2 给出