Selenium获取span innerhtml

时间:2018-03-21 13:51:04

标签: c# html selenium selenium-webdriver

<div id="ctl00_cphRoblox_rbxGroupFundsPane_GroupFunds" class="StandardBox" style="padding-right:0">
<b>Funds:</b> 
<span class="robux" style="margin-left:5px">128</span>
</div>

好的,所以我想得到128但有时它给了我&#34; 18&#34; 我不知道

我试过了:

dcWeb.SendMessage(s + " = Pending and Robux: " + driver.FindElement(By.ClassName("robux")).GetAttribute("innerHTML"));

dcWeb.SendMessage(s + " = Pending and Robux: " + driver.FindElement(By.ClassName("robux")).GetAttribute("textContent"));

1 个答案:

答案 0 :(得分:0)

要获取文字 128 ,您可以使用以下代码行:

dcWeb.SendMessage(s + " = Pending and Robux: " + driver.FindElement(By.XPath("//div[@class='StandardBox' and contains(@id,'_cphRoblox_rbxGroupFundsPane_GroupFunds')]//span[@class='robux']")).GetAttribute("innerHTML"));