![](/img/trans.png)
[英]how to get text present between html tags like <div>text</div> using selenium C#
[英]Using Selenium WebDriver in C#, how do I access the text between the opening and closing div tags?
所以我正在查看的頁面有一行:
<div class="page-curr">Page 1 of 10</div>
我假設一個簡單的
driver.FindElement(By.ClassName("page-curr")).Text
會工作。 頁面上沒有其他 page-curr 迭代。 刪除.Text時似乎找到了節點,但該節點中的文本為空。 我想我只是在錯誤的地方尋找它,但我不確定在哪里可以找到它。
使用顯式等待標記的內容為“非空”應該可以解決問題:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(d => !string.IsNullOrWhiteSpace(d.FindElement(By.ClassName("page-curr")).Text));
var text = driver.FindElement(By.ClassName("page-curr")).Text;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.