Reputation: 1126
I am working through the following table. I want to grab the value within the <td>
tag that contains 30.0000, but whenever I try to grab it with Selenium, it returns 0.0000. I have tried findElementByXPath(".//*[@id='ctl00_c_dgPOItems_ctl00__0']/td[6]).Text
where the text reads as:
<td align="center">30.0000</td>
No other selenium command seems to even find it. Does anyone know why I can not get the value out of this table? Thank you.
<tr id="ctl00_c_dgPOItems_ctl00__0" class="rgRow">
<td class="rgExpandCol">
<img style="border-width:0px;" alt="Collapse" src="/Images/icons/collapse-icon.png" onclick="$find("ctl00_c_dgPOItems_ctl00")._toggleExpand(this, event); return false;" title="Collapse"/>
</td>
<td>ROS50462</td>
<td>ENSURE CHOCOLATE ENTERAL FOOD UNIT/CAN</td>
<td>Can(s)</td>
<td style="width:50px;">
<span id="ctl00_c_dgPOItems_ctl00_ctl04_txtQuantity_wrapper" class="riSingle RadInput RadInput_Office2007" style="width: 40px;">
</td>
<td align="center">30.0000</td>
//rest of table....
Upvotes: 0
Views: 3723
Reputation: 42528
The text in your element is most probably equal to "0.0000" at the time you try to read it. I would try to exclude the default value and wait for it:
WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5));
WebElement element = wait.Until<IWebElement>(d => d.FindElement(
By.XPath(".//*[@id='ctl00_c_dgPOItems_ctl00__0']/td[6][text()!='0.0000']")));
Upvotes: 0
Reputation: 50909
You can try different approach. Locate the previous sibling and go from there
driver.FindElement(By.XPath("//[@id='ctl00_c_dgPOItems_ctl00_ctl04_txtQuantity_wrapper']/../following-sibling::td")).Text;
Upvotes: 2