简体   繁体   中英

How to extract the dynamic text inside <nobr> using selenium webdriver?

I am trying to fetch the server file name which is in text format in DOM inside a <nobr> tag and I am getting an invoker error.

Error

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 Code

<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>

What I had tryied so far

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

Also tried,

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

Hope this will work //nobr[contains(text(),'/aps')]

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM