[英].Text not working in Selenium PhantomJS C#
I want to get the text Sample
from this structure: 我想从这个结构中获取文本
Sample
:
<td id="IDName">Sample</td>
so I tried this: 所以我试过这个:
driver1.FindElement(By.Id("IDName")).Text;
but it always return null
. 但它总是返回
null
。
Is there any reason why is it not working? 有什么理由不起作用吗?
It's Hard to say why .Text
is not working in your case, Might be possible when you are going to find element it's present on the DOM
without text, So you should WebDriverWait
to wait until element exists as below :- 很难说为什么
.Text
在你的情况下不起作用,当你要在没有文本的DOM
上找到它存在的元素时可能是可能的,所以你应该等到元素存在,如下所示: - WebDriverWait
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("IDName")));
element.Text;
Or might be possible it's designing issues of your HTML, then you can get text by using .GetAttribute("innerHTML")
as below :- 或者可能是设计HTML的问题,然后您可以使用
.GetAttribute("innerHTML")
获取文本,如下所示: -
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("IDName")));
element.GetAttribute("innerHTML");
Or then you can get text by using .GetAttribute("textContent")
as below :- 或者您可以使用
.GetAttribute("textContent")
获取文本,如下所示: -
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("IDName")));
element.GetAttribute("textContent");
Hope it helps...:) 希望能帮助到你...:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.