下面是 html,我想获取文本“Conference USA”
<li class="list-unstyled" style="background-color: transparent;">
<input id="account" type="checkbox" checked="checked" value="101" name="account"
style="background-color: rgb(255, 255, 255);"/> Conference USA
</li>
最佳答案
根据您的问题和提供的评论,您并不清楚您到底想要什么。
因此,如果您希望 li
元素使用文本 Conference USA,请尝试以下操作:-
WebElement liElement = driver.FindElement(By.Xpath("//li[contains(.,'Conference USA')]"));
或者如果你想要 input
元素使用文本 Conference USA 尝试如下:-
WebElement inputElement = driver.FindElement(By.Xpath("//li[contains(.,'Conference USA')]/input"));
或者如果你想要 li
元素的文本 Conference USA 尝试如下:-
string text = driver.FindElement(By.Xpath("//li[./input[@type = 'checkbox' and @value='101']]")).Text;
希望对您有所帮助...:)
关于c# - 如何使用 Selenium webdriver 获取不在 html 标签内的元素文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38247833/