Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从<;获取文本;td>;使用硒标记_C#_Html_Selenium - Fatal编程技术网

C# 从<;获取文本;td>;使用硒标记

C# 从<;获取文本;td>;使用硒标记,c#,html,selenium,C#,Html,Selenium,我正在完成下表。我想获取包含30.0000的标记中的值,但每当我尝试使用Selenium获取它时,它都返回0.0000。我尝试了findelementbypath(“./*[@id='ctl00_c_dgPOItems_ctl00__0']]/td[6])。Text其中的文本内容如下: 30.0000 似乎没有其他selenium命令找到它。有人知道我为什么不能从这个表中获取值吗?谢谢 <tr id="ctl00_c_dgPOItems_ctl00__0" class="rgRow">

我正在完成下表。我想获取包含30.0000的
标记中的值,但每当我尝试使用Selenium获取它时,它都返回0.0000。我尝试了
findelementbypath(“./*[@id='ctl00_c_dgPOItems_ctl00__0']]/td[6])。Text
其中的文本内容如下:

30.0000

似乎没有其他selenium命令找到它。有人知道我为什么不能从这个表中获取值吗?谢谢

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

ROS50462
确保巧克力肠内食品装置/罐
罐头
30
//桌子的其余部分。。。。

您可以尝试不同的方法。找到以前的兄弟姐妹并从那里开始

driver.FindElement(By.XPath("//[@id='ctl00_c_dgPOItems_ctl00_ctl04_txtQuantity_wrapper']/../following-sibling::td")).Text;

你可以尝试不同的方法。找到以前的兄弟姐妹并从那里开始

driver.FindElement(By.XPath("//[@id='ctl00_c_dgPOItems_ctl00_ctl04_txtQuantity_wrapper']/../following-sibling::td")).Text;

在您尝试读取元素时,元素中的文本很可能等于“0.0000”。 我将尝试排除默认值并等待它:

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']")));
WebDriverWait wait=newwebdriverwait(驱动程序,新时间跨度(0,0,5));
WebElement=wait.Until(d=>d.FindElement(
By.XPath(“./*[@id='ctl00_c_dgPOItems_ctl00__0']]/td[6][text()!='0.0000']);

在您尝试读取元素时,元素中的文本很可能等于“0.0000”。 我将尝试排除默认值并等待它:

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']")));
WebDriverWait wait=newwebdriverwait(驱动程序,新时间跨度(0,0,5));
WebElement=wait.Until(d=>d.FindElement(
By.XPath(“./*[@id='ctl00_c_dgPOItems_ctl00__0']]/td[6][text()!='0.0000']);

查看以前的兄弟姐妹有什么好处?这是否使代码“从不同的角度”查看它,“因为缺少更好的词语吗?@Rinktacular您使用的
xpath
依赖于您希望成为六个
标记的位置。如果通过JavaScript添加/删除了一些标记,则会更改标记的相对位置,因此
td[6]
将不再相关。但这可能不会发生,也不会有任何区别。很有趣,谢谢!看看以前的兄弟姐妹有什么好处?这是否会让代码“从不同的角度”来看待它,因为没有更好的词语?@Rinktacular您使用的
xpath
取决于希望成为六个
标记的
位置。如果通过JavaScript添加/删除了一些标记,则会更改标记的相对位置,因此
td[6]
将不再相关。但这可能不会发生,也不会有任何区别。很有趣,谢谢!啊,我不感谢那件事,我会尽量等一会儿的。啊,我不感谢那件事,我会尽量等一会儿的