Selenium WebDriver C#-获取文本
问题描述:
我在页面上有这个HTML元素:
I have this Html element on the page:
<li id="city" class="anketa_list-item">
<div class="anketa_item-city">From</div>
London
</li>
我发现了这个元素:
driver.FindElement(By.Id("city"))
如果我尝试: driver.FindElement(By.Id( city))。Text
,=>我的结果是: From\r\nLondon。
If I try: driver.FindElement(By.Id("city")).Text
, => my result: "From\r\nLondon".
如何通过WebDriver仅获取伦敦?
How can I get only London by WebDriver?
答
通过使用 class-name
获取:
driver.FindElement(By.Class("anketa_item-city")).Text;
或使用 Xpath
driver.FindElement(By.Xpath("\li\div")).Text;