【问题标题】:Selenium on getting span innerhtmlSelenium 获取 span innerhtml
【发布时间】:2018-03-21 22:01:04
【问题描述】:
<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,但有时它会给我“18” 我不知道

我试过了:

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

【问题讨论】:

  • 你为什么不直接使用“.Text”而不是getAttribute

标签: c# html selenium selenium-webdriver


【解决方案1】:

要获取文本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"));

【讨论】:

    猜你喜欢
    • 2012-12-02
    • 2019-05-20
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 2020-09-04
    相关资源
    最近更新 更多