无法使用雅虎草稿邮件中的Webdriver获取草稿主题字段的值
本文关键字:获取 Webdriver 字段 雅虎 | 更新日期: 2023-09-27 17:59:03
>我在雅虎邮件中创建了草稿信,然后进入了这个草稿信页面。现在我想使用 C# 和 Selenium Webdriver 获取主题字段的值。我使用了以下代码,但它返回空字符串:
string subjectLocator = "//*[@id='subject-field']";
string actualSubject = driver.FindElement(By.XPath(subjectLocator)).GetAttribute("Value");
使用 Text 属性而不是GetAttribute
方法也无济于事。
如何使用Selenium
Webdriver
和C#
获取雅虎草稿信中主题字段的值?
http://prnt.sc/bye5ae - 网页代码
正如我看到您用来从主题字段中获取值作为.GetAttribute("Value")
,这里唯一的问题是将属性属性传递为应该value
Value
意味着v
应该是小写的,所以你应该尝试如下:-
string actualSubject = driver.FindElement(By.Id("subject-field")).GetAttribute("value");
或者使用 WebDriverWait
等待元素出现在DOM
上,如下所示:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("subject-field")));
string actualSubject = element.GetAttribute("value");
我已经测试过它,它对我有用。
希望对您有所帮助:)